在进行 git rebase 时,我经常很难弄清楚在解决冲突时“本地”和“远程”发生了什么。有时我的印象是他们从一次提交到下一次提交交换双方。
这可能(肯定)是因为我还没有正确理解。
rebase 时,谁是“本地”,谁是“远程”?
(我使用 P4Merge 来解决冲突)
最佳答案
TL; 博士;
总结一下(如 Benubird comments ),当:
git checkout A
git rebase B # rebase A on top of B
local
是 B
(rebase 到 2,1942 1942)remote
是 A
和:
git checkout A
git merge B # merge B into A
local
是 A
(将 merge 为 2 3 341142 29)remote
是 B
rebase 切换
ours
( rebase 开始前的当前分支)和 theirs
(要 rebase 的分支)。kutschkem 指出,GUI merge 工具上下文 中的 :
ours
”(上游分支)0x2931411theirs
” - rebase 前的当前分支。 请参阅本答案最后一部分中的插图。
rebase 时反转
混淆可能与 inversion of
ours
and theirs
during a rebase 有关。(相关摘录)
git rebase
man page:因此,当发生 merge 冲突时:
ours
”的一侧是迄今为止的重新调整系列,从 <upstream>
、 theirs
' 是工作分支。换句话说,双方互换。
反转图示
merge 时
x--x--x--x--x(*) <- current branch B ('*'=HEAD)
\
\
\--y--y--y <- other branch to merge
,我们不改变当前分支'B',所以我们所拥有的仍然是我们正在处理的(并且我们从另一个分支 merge )
x--x--x--x--x---------o(*) MERGE, still on branch B
\ ^ /
\ ours /
\ /
--y--y--y--/
^
their
在 rebase 上:
但是 在 rebase 上,我们切换一边,因为 rebase 做的第一件事就是检查上游分支! (在其上重放当前提交)
x--x--x--x--x(*) <- current branch B
\
\
\--y--y--y <- upstream branch
A
git rebase upstream
将首先将 B 的 HEAD
更改为上游分支 0x251812241 's''s''s 's''s''x--x--x--x--x <- former "current" branch, new "theirs"
\
\
\--y--y--y(*) <- upstream branch with B reset on it,
new "ours", to replay x's on it
,然后 rebase 将在新的“我们的”B 分支上重放“他们的”提交:
x--x..x..x..x <- old "theirs" commits, now "ghosts", available through reflogs
\
\
\--y--y--y--x'--x'--x'(*) <- branch B with HEAD updated ("ours")
^
|
upstream branch
注意:"upstream" notion 是引用数据集(一个所有的 repo 或像这里一样的一个分支,它可以是一个本地分支),从中读取数据或向其中添加/创建新数据。
“
HEAD
”和“local
”对比“remote
”和“mine
”Pandawood 添加 the comments :
GUI git merge 工具
kutschkem 补充说,正确的是:
local: modified file and remote: modified file.
theirs
”(上游分支)0x2423191ours
” - rebase 前的当前分支。 theirs
确实提到了“本地”和“远程” :Merging:
f.txt
Normal merge conflict for 'f.txt':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (kdiff3):
例如, KDiff3 将 display the merge resolution like so :
和 meld 将 display it too :
VimDiff 、 which displays 相同:
+--------------------------------+
| LOCAL | BASE | REMOTE |
+--------------------------------+
| MERGED |
+--------------------------------+
关于git rebase,跟踪 'local' 和 'remote',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3051461/