1

EDIT: Thanks for the replies everyone, but my apologies - I was looking at an old file (that I hadn't worked on in while) the latest version of my app was copied over when I backed up the directory.


I was working on an app, but forgot to commit changes before formatting the drive/reinstalling the OS. I did take a copy of my app directory (which includes the .git directory) beforehand.

Is it possible to recover the files I was working on that were not committed at the time of back up?

I've restored the backup directory of the app, but it appears to be the state of the last commit.

Not a major headache if it's not possible as there weren't that many changes, but still - would be nice to not lose any work.

A4J
  • 879
  • 10
  • 24
  • 1
    What's odd about this question is why the copy of the app directory didn't pick up the changes. How did you make the backup? – Christopher Aug 10 '12 at 20:31
  • I just dragged my projects folder which contains the app's directory onto my external disk. – A4J Aug 10 '12 at 20:42
  • @A4J if you copied the whole working directory then I'd expect you to have have all the uncommitted changes, without having to resort to git. It seems very strange that that's not the case. – bames53 Aug 10 '12 at 20:44
  • I'm with @barnes53. There's nothing about that procedure that would abandon your unstaged changes. Are you sure they were in place when you made the copy?... sort of a moot point either way, but very odd. – Christopher Aug 10 '12 at 20:47
  • Sorry everyone - my mistake! I was looking at a file I hadn't worked on in a while, and the rest of the app is as it was when I last worked on it. – A4J Aug 10 '12 at 20:52
  • Git isn't magic. If you ask Git not to track a file, Git *doesn't track the file*. Voted to close as the premis of this question is pretty ridiculous. – user229044 Aug 10 '12 at 21:01
  • 1
    @Maegar - perhaps you should read the full question before posting comments in future. – A4J Aug 10 '12 at 21:09

3 Answers3

2

That depends on if you stashed the changes or not I would think. If you didn't, I would say no.

If you haven't looked into stashing, maybe you should consider it in the future. Stashing allows you to keep a working backup of your code without you having to commit it. That way if your code is in a messy, unusable state, you can back it up without committing.

Stashing

Devo
  • 301
  • 2
  • 12
2

I'm sorry, you cannot get back uncommitted changes using Git. But @sehe has some good suggestions for other places to find your changes.

  1. Does your editor autosave backups of each file? (e.g. Vim's bak~ files)
  2. /tmp or C:\Temp.
  3. Eclipse local settings
Community
  • 1
  • 1
Troy Harvey
  • 2,331
  • 1
  • 20
  • 18
1

No. If git never was informed about the changes (through commits), then how could it retrieve the changes?

That said, if you want a list of any changes, stashes, etc, that git -is- aware of, you can use git reflog to review all the recent actions.

Kzqai
  • 22,588
  • 25
  • 105
  • 137