1

While experimenting with Git, I changed a file's content from 1 to 100, and was able to commit and see it in the log. But after some more test and

git checkout <some_hash>      // I think this is to revert the whole repo to a 
                              //     certain state

git checkout master           // And this is to change the repo to the most 
                              //     current state

the commit histories were lost in git log. What happened -- could the commit have gone into another branch and how to view it or get it back?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740

1 Answers1

4

It's hard to say exactly where the commit went without knowing exactly what you did. However, the git reflog command will show the positions that the current branch head has been in the past, including commits that may no longer be in the history.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • yes, the commit will show using `git reflog`, and the line and the one before it are: `d3fb496 HEAD@{11}: commit: version 100` and `6726b65 HEAD@{12}: checkout: moving from f1f06d8291ef90e53440... to 6726b...` and then if I use `git checkout f1f0`, then `git log` will show the commit. (by the way, is there a way to see all the branches and commits in a text graph or image graph. Maybe that will show too?) – nonopolarity Aug 27 '12 at 04:19
  • @動靜能量: You may find `git show-branch` and `gitk` useful; there are also other tools that show the Git branch tree. However, most of show only branches that are "reachable", that is they have names of some kind (a head, a tag, etc). It is possible to have commits that can be found only by knowing the commit id (as it sounds like you might have here). – Greg Hewgill Aug 27 '12 at 04:54
  • interesting, if `git show-branch`, I only see 1 branch, so what is the "branch" of `git checkout f1f0`? Because when I do that, I see commit that I don't see otherwise – nonopolarity Aug 27 '12 at 05:44
  • 1
    There's a good explanation of this situation at this related question: http://stackoverflow.com/questions/3965676/why-did-git-detach-my-head You can find other descriptions of the situation by searching for "detached head". It's basically a branch that doesn't have a name yet. – Greg Hewgill Aug 27 '12 at 09:07