[英]Why does a cherry-pick cause git merge to discard part of my commit?
So I'm trying to understand why when I git merge master
into a branch, I lose some, but not all of my changes in a commit.所以我试图理解为什么当我git merge master
到一个分支中时,我会丢失一些,但不是我在提交中的所有更改。 It seems to do with a cherry-pick commit on my branch.这似乎与我的分支上的樱桃选择提交有关。 Here's how to reproduce:以下是如何重现:
git merge master
Go 回测试,运行git merge master
master
.我希望合并不会删除该行,以便它匹配master
。I uploaded my results on github: https://github.com/terryttsai/testRevertMerge/commits/test我在 github 上上传了我的结果: https://github.com/terryttsai/testRevertMerge/commits/test
If I never cherry-picked that commit into my test
branch, then git merge master
does keep that line of text.如果我从来没有将那个提交挑选到我的test
分支中,那么git merge master
确实保留了那行文本。 So how come when I do have that cherry-pick commit, the merge removes it?那么,当我确实有那个cherry-pick 提交时,怎么会被合并删除呢? How can I prevent this from happening in the first place?我怎样才能首先防止这种情况发生?
I expect the merge to not drop that line, so that it matches master.我希望合并不会删除该行,以便它与 master 匹配。
No. git merge master
does not mean to match master!号git merge master
不代表匹配高手!
What is a merge?什么是合并? A merge means to play out the contributions of both branches, starting from the point of divergence.合并意味着从分歧点开始发挥两个分支的贡献。 What are they?这些是什么?
Well, the point of divergence is after that first line was added.好吧,分歧点是在添加第一行之后。 So what happened after that on each branch?那么在每个分支之后发生了什么?
On master, the only contribution is the extra stuff.在master上,唯一的贡献是额外的东西。 (It removed the first line but later restored it, so that is not a contribution; in that respect nothing happened at all.) (它删除了第一行,但后来又恢复了它,所以这不是贡献;在这方面什么也没发生。)
On test, the only contribution is deletion of the first line (that is what the cherry picked revert commit does).在测试中,唯一的贡献是删除第一行(这就是樱桃选择的还原提交所做的)。
So the merge does both of them: the extra lines from master, and the deletion from test.所以合并完成了它们:master 中的额外行,以及 test 中的删除。
But if you never do the cherry pick, then neither branch makes a contribution that deletes that line, so obviously it is not deleted by the merge.但是,如果您从不进行樱桃挑选,那么两个分支都不会做出删除该行的贡献,因此显然它不会被合并删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.