In TortoiseGit, which one is MERGE_HEAD and which one is HEAD?
In TortoiseGit, which one is MERGE_HEAD and which one is HEAD?
They are both local (this is important, albeit not very helpful :-) ).
HEAD
is your current branch, which means the one you have checked out now. For git merge
that's the one you had checked out when you started.
MERGE_HEAD
is the other commit, which means the hash ID of the commit you told Git to merge. That is, git merge origin/master
resolves origin/master
to some local commit hash ID, and then merges that commit, and MERGE_HEAD
contains the hash ID of that commit.
I think a better term for the other commit is other or --theirs
, and Git sometimes uses those terms, but other bits of Git do use the term remote to refer to the --theirs
commit.
MERGE_HEAD vs HEAD in Git
In Git, HEAD
is a pointer to the current branch, which points to the most recent commit in that branch. The HEAD
pointer is updated automatically when new commits are made to the current branch.
MERGE_HEAD
is a pointer to the most recent commit in the branch that was merged into the current branch during a merge operation. When you perform a merge in Git, the MERGE_HEAD
pointer is updated to point to the most recent commit in the merged branch.
So, while HEAD
points to the most recent commit in the current branch, MERGE_HEAD
points to the most recent commit in the branch that was just merged into the current branch.
It's worth noting that MERGE_HEAD
is a temporary pointer that is only valid during a merge operation, and it is reset after the merge is complete. On the other hand, HEAD
is a long-lived pointer that is always present in a Git repository.
What's the merged branch you mentioned above? demonstrate the concept with an sample
In Git, merging refers to combining changes from one branch into another branch. When you merge one branch into another branch, Git creates a new commit that incorporates the changes from both branches.
Let's say we have two branches: master
and feature-branch
. Initially, both branches point to the same commit in the Git history:
A (master, feature-branch)
Then, we make some changes on the feature-branch
:
A (master)
\
B (feature-branch)
Now, if we want to incorporate the changes from feature-branch
into master
, we can merge feature-branch
into master
:
A ---- C (master)
\ /
B (feature-branch)
In this example, C
is the new commit that results from the merge. It contains the changes from both A
and B
.
After the merge, Git updates the HEAD
reference to point to the new commit C
, which is the latest commit on the master
branch. This means that HEAD
now refers to C
.
MERGE_HEAD
, on the other hand, is a reference that Git creates during the merge operation. It points to the latest commit on the branch that was merged into the current branch. In the example above, after the merge, MERGE_HEAD
would point to commit B
, which is the latest commit on feature-branch
.
MERGE_HEAD
is used by Git to keep track of the merge operation. It allows Git to create a new commit that incorporates the changes from both branches, and to update the branch pointers to point to the new commit.
Note that MERGE_HEAD
is a temporary reference that is created during the merge operation and is deleted once the merge is complete.