1

I have a git repository. When I do 'git branch', it said

 $ git branch
* com-2.1-SS

and then I do 'git log', i get a list of my commit

$ git log
commit ff878926b78614e8bf6af161da06070618e9ff6b

commit 3ffda8cec60a74a718fb25fb7a9fe4b3c4381137

commit bf6bb3427d8031d8e172c3b8b7909c8580e929cd

So I want to check out my repository to 3ffda8cec. So I did 'git checkout 3ffda8cec'.

So far so good. It works and I get want I want.

But my question is how can I get back to com-2.1-SS? i.e. reverse the fact that I 'git checkout 3ffda8cec'

When I do 'git branch', it said

$ git branch
* (no branch)

When I do 'git checkout git checkout com-2.1-SS

error: pathspec 'com-2.1-SS' did not match any file(s) known to git.
2
  • Can you double check your output. Your original branch output said you have exactly one branch (com-2.1-SS) but your second git output says you have no branches at all but nothing you've said you've done should have wiped out your branches. The command that should work is git checkout com-2.1-SS, not git checkout git checkout com-2.1-SS1.
    – CB Bailey
    Commented Aug 27, 2012 at 8:19
  • 2
    As @CharlesBailey said, it seems that between your two calls to git branch you removed the branch named com-2.1-SS (if you have used only git commands, you probably have used git branch -D com-1.2-ss) this is the most sensible explanation for your error. Commented Aug 27, 2012 at 8:28

1 Answer 1

2

git reflog will show you the different values a branch tip had and you can checkout it to go back to a previous state.

Your case is easier since you still know now that the sha1 of com-2.1-SS before the git checkout was ff878926b78614e8bf6af161da06070618e9ff6b (which is basically what git reflog do) so you can directly do:

git checkout ff878926b78614e8bf6af161da06070618e9ff6b

Althoug I don't understand from your description at which point your branch was deleted, you can recreate your branch after the checkout with:

git checkout -b com-2.1-SS
2
  • No that your answer is wrong, but AFAICT the OP here just checked out 3ffda8cec without removing com-2.1-SS (headless mode) and seems to not be able to checkout com-2.1-SS again. I'm not sure that reflog helps with anything here. But in the end, doing a git checkout -B com-2.1-SS ff878926b should indeed solve the issue. Commented Aug 27, 2012 at 8:26
  • I did not delect the branch. I don't understand why it is 'gone' after I check out to a SHA.
    – michael
    Commented Aug 27, 2012 at 8:44

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