There seems to be a difference between the last commit, the HEAD and the state of the file I can see in my directory.
What is HEAD, what can I do with it and what mistake should I avoid?
HEAD^ means the first immediate parent of the tip of the current branch. HEAD^ is short for HEAD^1 , and you can also address HEAD^2 and so on as appropriate. The same section of the git rev-parse documentation defines it as. <rev>^ , e.g. HEAD^ , v1.5.1^0.
In Git, a head is a ref that points to the tip (latest commit) of a branch. You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.
The master itself is a pointer to the latest commit. The HEAD is a reference that points to the master. Every time you commit, Git updates both master and the HEAD pointers to point to the last commit by default.
It represents the default branch on a remote and is a local ref representing a local copy of the HEAD in the remote repository. In summary, origin/HEAD represents the default branch on the remote, which is defined automatically when you clone a repository from the internet.
HEAD is a reference to the last commit in the currently checked-out branch.
There is a small exception to this, which is the detached HEAD. A detached HEAD is the situation you end up in whenever you check out a commit (or tag) instead of a branch. In this case, you have to imagine this as a temporary branch without a name; so instead of having a named branch reference, we only have HEAD. It will still allow you to make commits (which will update HEAD), so the above short definition is still true if you think of a detached HEAD as a temporary branch without a name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With