Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORIG_HEAD, FETCH_HEAD, MERGE_HEAD etc

Tags:

git

There's a lot of useful git references (what is the exact name for this?), e.g. HEAD, ORIG_HEAD, FETCH_HEAD, MERGE_HEAD, @{upstream} etc.

Is there any reference for this? A complete list with explanations?

like image 829
takeshin Avatar asked Jul 11 '13 14:07

takeshin


People also ask

What is Orig_head in git?

ORIG_HEAD is created by commands that move your HEAD in a drastic way, to record the position of the HEAD before their operation, so that you can easily change the tip of the branch back to the state before you ran them. MERGE_HEAD records the commit(s) which you are merging into your branch when you run git merge.

What is MERGE_HEAD?

MERGE_HEAD is the commit you name in your request to perform the merge, e.g., git merge bob to merge the the commit at the tip of branch bob ; and both commits are sources. There's a third source as well, which is the merge base commit, which Git computes for you.

What is fetch_ HEAD in git?

FETCH_HEAD is a short-lived ref, to keep track of what has just been fetched from the remote repository. git pull first invokes git fetch , in normal cases fetching a branch from the remote; FETCH_HEAD points to the tip of this branch (it stores the SHA1 of the commit, just as branches do).


2 Answers

git help revisions brings up http://git-scm.com/docs/gitrevisions, which describes all the the most common ways to reference commits:

  • HEAD names the commit on which you based the changes in the working tree.
  • FETCH_HEAD records the branch which you fetched from a remote repository with your last git fetch invocation.
  • ORIG_HEAD is created by commands that move your HEAD in a drastic way, to record the position of the HEAD before their operation, so that you can easily change the tip of the branch back to the state before you ran them.
  • MERGE_HEAD records the commit(s) which you are merging into your branch when you run git merge.
  • CHERRY_PICK_HEAD records the commit which you are cherry-picking when you run git cherry-pick.

From the git source, you can also find out about BISECT_HEAD, REVERT_HEAD, REJECT_NON_FF_HEAD and several others that you will almost certainly never need.

That reference also explains suffixes (^N, ~N, @{...}), ranges (.. vs ...), and more.

like image 82
dahlbyk Avatar answered Sep 21 '22 23:09

dahlbyk


HEAD: The current ref that you’re looking at. In most cases it’s probably refs/heads/master

FETCH_HEAD: The SHAs of branch/remote heads that were updated during the last git fetch

ORIG_HEAD: When doing a merge, this is the SHA of the branch you’re merging into.

MERGE_HEAD: When doing a merge, this is the SHA of the branch you’re merging from.

CHERRY_PICK_HEAD: When doing a cherry-pick, this is the SHA of the commit which you are cherry-picking.

The complete list of these refs can be found by cloning git sources:

git clone https://github.com/git/git.git

and grepping the _HEAD" string in .c files. They are dispersed all over the place, but still can be easily found.

P.S.

git help revisions does not show the list of all possible named refs.

like image 25
Sergey K. Avatar answered Sep 17 '22 23:09

Sergey K.