Reputation: 5630
As a result of my experimenting with switching between two commits, I have ended up in a situation where GitExtensions reports (no branch)
for my repository. Here's the output from git reflog
:
I haven't use branches, or intentionally anyway. My last commit was 91d96ff
. I then started the experimenting. I checked out the previous commit (699415c
) and confirmed that the working set had reverted to the files as they were at that commit (except for the datestamps - I can't get used to that!). I then checked out 91d96ff
again and then bounced a couple of times between these two commits, the last checkout leaving the head at 91d96ff
, where it was when I started. I have made changes to the sources since the last commit.
Here's how GitExtensions shows it:
And I notice that the little red triangle that is normally next to the Master
is missing - I assume that indicates where the head is (or isn't in this case). I presume I have a detached head?
Why is Git reporting this "no branch"? What is the clean and proper way to recover from this? Is GitExtension's Reset current branch to here
all I need?
I'm curious to know what I might have done to end up in this state.
Upvotes: 1
Views: 957
Reputation: 5630
I thought I would detail the steps that gave rise for the OP. I have been using GitExtensions for all my Git-related stuff.
Originally, my repo status looked like below and I was experimenting with checking out earlier commits, so I right-click and choose Checkout revision
:
After that, the appearance was:
Note the (no branch)
displayed, and the fact that the master
node is grayed out. Having confirmed that what happened to the working set was what I hoped would happen, I then reverted back to the original state with:
Which got me back to the original working set presumably, but still with no branch
. What I should have done was:
Upvotes: 0
Reputation: 3388
You probably did the equivalent of checking out a commit, like so: git checkout 91d96ff
This will put you in a detached state, which is what your UI means when it reports "no branch".
The best thing to do to get back to "normal" would be to git stash
your local changes, then git checkout master
(or whatever branch you were originally working with) Then git stash pop
to restore the local changes that you may have had. If there are any conflicts, they will be presented to you at that point.
This was caused by the fact that you were "checking out" different commits.
Upvotes: 1