2

I have just a master branch in my git repo. I commited a change to my file yesterday night:

git add filename
git commit -m 'my message'

This morning I was making some more changes that later I wanted to revert (I had not added these changes to the index, they were only in my filesystem). I had a look here and used the following command:

git checkout path/to/file/filename

Now I noticed that my las commit was gone. I did a search and found this, but it refers to git revert.

If I do git log, my last commit shows up there, but the changes in the file are not. And if I do git status I get no changes showing and "nothing added to commit" message.

Why did it revert my last commit? How do I re-apply the commit?

Thanks in advance.

Community
  • 1
  • 1
Esclapes
  • 45
  • 4
  • I couldn't reproduce this. EDIT: Okay, I realise that doesn't mean much. Maybe you could create a test repository and test for this behaviour? and `reflog` should give you your work best. Best of luck! – Unapiedra Aug 12 '11 at 09:14
  • Thanks. I did git reflog and it shows all my commits. – Esclapes Aug 12 '11 at 09:22
  • If this should not be happening, I will doubleckeck whether the changes were really reverted. – Esclapes Aug 12 '11 at 09:23
  • Yep, know I see in the git log -p that I did add several files, but not the one I did checkout today... I didnt see it listed as Modified in the git status, thogh... any way I think I can reapply changes manually – Esclapes Aug 12 '11 at 09:39

1 Answers1

2

If for whatever reason your commit from yesterday has disappeared, the first place to look for said commit is in the reflog.
See for instance "how to undo a checkout in git?"

git reflog
git reset --hard <sha from reflog><

You can even "Query git reflog for all commits to a specific file".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, I have a lot to learn with git, just started this week. Will checkout your links. Looking at the log -p I saw that some files were well add to the commit, while others were not. I did add them by the extension git add *.png and add *.css (may be I was in the wrong pwd) – Esclapes Aug 12 '11 at 09:54