Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the HEAD in git?

Tags:

git

head

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?

like image 358
e-satis Avatar asked Mar 27 '10 16:03

e-satis


People also ask

What is head and head in git?

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.

Where is the head in git?

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.

What is head and master in git?

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.

What is head in git origin?

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.


1 Answers

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.

like image 57
poke Avatar answered Sep 21 '22 03:09

poke