Reputation: 31248
I wanted to rewind back several commits because some of my coworkers broke the build in their recent changes. So I did
git checkout 7bb648abd7381bee5b92c18ff215b4f8a38935ee
Where 7bb648abd7381bee5b92c18ff215b4f8a38935ee is a commit four commits ago.
However, when I did
git status
it returned
# Not currently on any branch.
nothing to commit (working directory clean)
Why didn't it tell me that I was in the same branch but only four commits behind?
Upvotes: 1
Views: 66
Reputation: 4035
You are in a detached head state. See this answer https://stackoverflow.com/a/5772882/1049112 for an excellent explantion of what it means to have a detached head.
Branches (and all heads) only point to a single commit. You are not 'on' a branch unless you do a git checkout <branchname>
. Anytime you do another git checkout <something else>
you are no longer on that branch.
Upvotes: 1
Reputation: 14609
Indeed, you've checked out a commit, not a branch. If you want to move the branch you should do, after your checkout
:
git branch -f myBranchName #or "master" if it's the branch you're working on
it will move the branch myBranchName
if it already exists.
However, beware: you're going to change a shared history, so make sure you warn every people working on this branch.
Note that Git won't let you push it so easily (to ensure you know what you're doing): you'll have to push -f
Upvotes: 2