8

I'm using git gui and I can't see my branch.

I know I checked something in today.

I changed to an earlier branch after I did my commit and verified it with the branch viewer. I made changes to the earlier branch and then wanted to go back to my current branch, but I can't see it any more. Any help would be great.

1 Answer 1

27

In answer to your question, in most circumstances it is very hard to lose a recent commit by accident. Usually objects (including commits) only get removed after a git gc if they are no longer referred to by any branch and they are very old (by default 90 days IIRC).

Usually you can find the commit in your reflog. Try either of:

git log -g

or:

git reflog

If you can see it, it probably has a reference of the form HEAD@{n} where n is the number if times your HEAD has changed since the commit you've lost.

You can create a branch for it.

git branch foundit HEAD@{n}  # replace n with the correct number

Then you can decide if you need to merge it in to another branch or rebase it or just keep the branch around for later.

5
  • 1
    Ah.. I forgot the -g THANK YOU SO MUCH
    – baash05
    Mar 22, 2010 at 21:55
  • It's rare to lose commits. Roughly how old would the commit be? The other option is to use git fsck and see if you have any dangling commits but if you have a lot it can be harder to find the correct one as you tend to have to git show a lot of commits individually to try and identify them.
    – CB Bailey
    Mar 22, 2010 at 21:56
  • Any reason why the gui wouldn't show this same info? Do people use the GUI?
    – baash05
    Mar 22, 2010 at 21:57
  • @baash05: Probably not for hunting down lost commits; the command line is usually more powerful. There's no particular reason why a GUI couldn't provide this feature, though.
    – CB Bailey
    Mar 22, 2010 at 22:00
  • @baash05 - in general git commands don't lose commits, even if git crashes horribly you can find your commits in the reflog. Don't forget to upvote and accept the answer if it solves your problem.
    – orip
    Mar 22, 2010 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.