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.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-01-21 RedGate support tickets
2019-01-21 Autofac Getting Started(默认的构造函数注入)
2019-01-21 Autofac Controlling Scope and Lifetime
2019-01-21 Autofac register and resolve
2019-01-21 What's the difference between UTF-8 and UTF-8 without BOM?
2016-01-21 Finalization