HEAD is a pointer, and it points — directly or indirectly — to a particular commit:
Attached HEAD means that it is attached to some branch (i.e. it points to a branch).
Detached HEAD means that it is not attached to any branch, i.e. it points directly to some commit.
In other words:
- If it points to a commit directly, the HEAD is detached.
- If it points to a commit indirectly, (i.e. it points to a branch, which in turn points to a commit), the HEAD is attached.
To better understand situations with attached / detached HEAD, let's show the steps leading to the quadruplet of pictures above.
We begin with the same state of the repository (pictures in all quadrants are the same):
Now we want to perform git checkout
— with different targets in the individual pictures (commands on top of them are dimmed to emphasize that we are only going to apply those commands):
This is the situation after performing those commands:
As you can see, the HEAD points to the target of the git checkout
command — to a branch (first 3 images of the quadruplet), or (directly) to a commit (the last image of the quadruplet).
The content of the working directory is changed, too, to be in accordance with the appropriate commit (snapshot), i.e. with the commit pointed (directly or indirectly) by the HEAD.
So now we are in the same situation as in the start of this answer:
git checkout master
will get you back on the master branch. If you wanted to clear out any working copy changes, you probably wanted to dogit reset --hard
. – Abe Voelkergit checkout -- src/
– thesummersigncreate temp branch - checkout temp branch - checkout master - delete temp branch
– fidevworking copy changes
? Are you referring to the changes you made to files after checking out another commit (i.e., the changes you made while in a detached head state)? – Minh Tran