6

I had checked out an old hash (commit) and was working on it, checking in merrily and ignoring warnings that I wasn't working in a branch. Then I switched to a branch and realized that I had no way to get back to my orphaned checkins (luckily I had the terminal window open still, so I checked it out and branched).

How can I get GIT to tell me the names of the commits that do NOT belong to a branch? Or just all the commits, if that's not possible...

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • "checking in merrily and ignoring warnings". Well, that goes to show: You can ignore warnings, but you should know what you are doing :-). – sleske Sep 17 '12 at 10:33
  • 1.5 years later, reading the question and answers over, I don't think it goes to show that at all, but perhaps the opposite: eventually it will all be clear. – Dan Rosenstark Sep 17 '12 at 15:34

3 Answers3

7

git reflog will show the log of the references created by recent activity you've done. For future reference, git checkout of a commit puts you on an detached head. If you want to base work on an old commit, you should create a branch off of that commit instead.

git checkout -b newbranch oldsha1

or

git branch newbranch oldsha1
git checkout newbranch
jamessan
  • 41,569
  • 8
  • 85
  • 85
2

You can fish them out of the reflog, which stores the commits which you've had checked out.

git reflog will print out the most recent commits pointed to by HEAD, which is your working copy.

You can also get a list of all objects in your tree which are unreachable from your current branches using git fsck.

Andrew Aylett
  • 39,182
  • 5
  • 68
  • 95
2

See this question which has a great explanation of how to find stashes you've dropped. You can see dangling commits etc. the same way.

Community
  • 1
  • 1
John Stoneham
  • 2,485
  • 19
  • 10
  • Man that is awesome. I don't use stash yet but it opens the door. Thanks John. – Dan Rosenstark Feb 01 '10 at 19:21
  • 2
    Oh man, you'll never stop once you learn it. Stashing changes to try them on different branches, to test merges, to switch between three different versions of a change, to get rid of half your change without losing the other half forever... – John Stoneham Feb 03 '10 at 02:55
  • never saw your comment here because it had no @yar in it :)... anyway, yes, I'm still learning new stuff on GIT daily – Dan Rosenstark Feb 24 '10 at 18:01