支持变革的命令您当地的分行 is:
git pull --rebase -X theirs
直觉上,当你想说“我们的”时,你必须说“他们的”,因为与合并相比,“我们的”和“他们的”的含义在变基期间交换了。让我解释。
我们和他们的合并与变基
当你进行合并时,你总是合并到当前分支;如果发生冲突,“我们的”是指你所在的分行,而“他们的”意味着您要合并的分支。正如您所期望的那样。
变基则不同。假设您正在重建一个名为local
onto master
.
master
⌄
o---o---o
\
A---B---C ‹ local
During a rebase, Git creates a sort of "temporary branch" to do the work1. It starts by moving HEAD
to the tip of the branch you're rebasing onto, in this case master
:
master
⌄
o---o---o ‹ HEAD
\
A---B---C ‹ local
然后,它从以下位置挑选提交:local
一次一个:
master
⌄
o---o---o---A'---B' ‹ HEAD
\
A---B---C ‹ local
现在,让我们想象一下提交的情况C
有冲突:
master
⌄ X
o---o---o---A'---B'---C' ‹ HEAD
\
A---B---C ‹ local
在这种情况下,“ours”表示 Git 正在处理的临时分支,而“theirs”是从中挑选提交的分支,即local
.
如果您想保留更改local
分支,你必须选择“他们”的一方。相反,如果您想将更改保留在master
,你会选择“我们的”一方。
一旦冲突解决,Git 通过移动来完成变基操作local
指向哪里HEAD
is:
master
⌄
o---o---o---A'---B'---C' ‹ HEAD, local
\
A---B---C
鉴于没有分支留下引用提交C
,这些提交变成无法到达的 https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefunreachableobjectaunreachableobject最终将被删除:
master
⌄
o---o---o---A'---B'---C' ‹ HEAD, local
1 It's really just a detached head https://git-scm.com/docs/git-checkout#_detached_head, but for the purpose of this explanation, you can think of it as a temporary branch, even though no branch reference is being created.