0

Edit: I was able to get back the file by looking in the Team > Local History section of Eclipse. Still, this seems like strange behavior from git. It seems like destructive behavior should have a warning by default.

It seems I've allowed git to lull me into a false sense of security and have lost some work. But hopefully I'm misunderstanding something.

Situation:

I made a bunch of changes to a file "page_classes.py". I realized I had made a bad change and wanted to see how an old version looked, so I followed the directions from (How do I restore files to previous states in git?) and did

git checkout c154ac3a6b1b723226c5b49ed6acaae614bed030 search_engine/page_classes.py

I saw what I wanted, then wanted to go back to what I was working on, so I did:

git checkout lastfm search_engine/page_classes.py

(lastfm being the branch I was working on.)

Upsettingly, page_classes.py only reverted to its state as of my last commit, which was about an hour ago (i.e. before I made a bunch of changes.)

I neither committed nor staged the changes (because I've come to assume that git will never destroy work without at least a warning), but now it seems I cannot get my work back. This answer suggests as much: (Git is it possible to revert unstaged files after a checkout)

Am I wrong that the work is gone? And if so, am I wrong to be surprised that git would overwrite and discard the new version of my file with no warning?

Community
  • 1
  • 1
rogueleaderr
  • 4,671
  • 2
  • 33
  • 40
  • 2
    Haven't you ever noticed what it says when you type `git status`? The stuff about using `git checkout -- file` to discard changes? You just ran a variation of that exact command. That's probably why they don't warn you. – Brandon Mar 07 '13 at 04:51
  • Indeed it does say that. Too bad I never read it until now. – rogueleaderr Mar 07 '13 at 04:53

0 Answers0