要解决合并冲突,我如何看到其他分支所做的更改? [英] To resolve a merge conflict, how do I see what change the other branch was making?
问题描述
我使用 git pull --rebase
从存储库中取出最新的代码。我的本地提交与其中一个远程提交发生冲突。有问题的文件中有合并标记,所以我可以将我的版本与他们的版本进行比较,但是我真正想知道的是其他版本试图做出的更改是什么?我想将其他变化与我们共同的祖先区分开来。如何做到这一点?
(编辑:gah,我有一个破碎的图表和描述,让我们来修复它:)
该命令将显示它们已更改的所有内容,您可能希望将更改隔离为特定提交或一组提交和/或文件在这些提交中,但考虑做:
$ b $ $ $ $ $ g $ diff $ $(git merge-base master origin / master)origin / master
(假设您位于分支 master
) 。这告诉git将共同的祖先提交与他们的头部提交进行比较。
下面是关于发生了什么的粗略草图。假设你以提交 A
, B
和 C
从 origin
(您克隆的回购)获得。你提交了 D
和 E
并且他们做了 F
和 D
中的更改已成功更新,并提交了 D'
,问题在于 E
。) + i,w
表示索引和/或工作目录中有东西还没有承诺 - 这是提交冲突,你需要解决。
D - E < - master
/
A - B - C D'+ i,w < - HEAD(分离)
\ /
F - G < - 原点/主轴
在这种情况下, git merge-base master origin / master
found提交 C
,这是rebase的共同点。
同时 origin / master
名称提交
G
。所以:
git diff<提交名称-C>起源/主
显示了他们所做的一切,在提交 F
和
G
(将 G
的内容与 C
)。当然,您也可以使用
git log
查找单个提交,或者使用 origin / master〜1
。您也可以使用 git show origin / master
查看最近的更改 G
和 git show origin / master〜1
来显示它们的变化 F
。
,如果一旦你解决了冲突和 git rebase --continue
并且到达最后,git会移动分支标签( master
)到 HEAD
点,并设置 HEAD
来引用 master code>,而不是分离。或者,如果你使用
git rebase --abort
,它会放弃新的链,然后恢复旧的 master
你可以在 rebase
稍后)。
(顺便说一句,这是一种情况,像 gitk
派上用场,调出 gitk --all 或
gitk HEAD master origin / master
在一个冲突的rebase上,通常很容易看出冲突的提交是在哪里。)
对于非常棘手的合并案例,有 git-imerge ,我还没有用过(但),但看起来非常漂亮。
I pulled the latest code from the repository with git pull --rebase
. My local commit conflicts with one of the remote commits. The file in question has the merge markers in it, so I can compare my version to their version, but what I really want to know is what change was the other version trying to make? I want to diff the other change to our common ancestor. How do I do that?
(Edit: gah, I had a broken diagram and description, let's fix it:)
This command will show everything that they changed, and you might want to isolate the changes to a specific commit or set of commits and/or files within those commits, but consider doing:
$ git diff $(git merge-base master origin/master) origin/master
(assuming you're on branch master
). This tells git to compare the common ancestor commit to "their" head commit.
Here's a rough sketch of what's going on. Suppose you started with commits A
, B
, and C
obtained from origin
(the repo you cloned). You made commits D
and E
and they made F
and G
. You're now in the middle of a conflicted rebase. (I've assumed here the change in D
was rebased successfully, giving commit D'
, and the problem is at E
.) The +i,w
means there is stuff in the index and/or working directory that is not yet committed—that's the commit with conflicts, that you need to resolve.
D - E <-- master
/
A - B - C D' +i,w <-- HEAD (detached)
\ /
F - G <-- origin/master
In this case, git merge-base master origin/master
finds commit C
, the common point for the rebase.
Meanwhile origin/master
names commit G
. So:
git diff <name-of-commit-C> origin/master
shows you everything they did, in both commits F
and G
(compares contents of G
to contents of C
). Of course, you can also use git log
to find the individual commits, or name them with names like origin/master~1
. You can also do git show origin/master
to look at their most recent change G
, and git show origin/master~1
to show their change F
.
Eventually, if once you resolve conflicts and git rebase --continue
and it reaches the end, git will move the branch label (master
) to where HEAD
points, and set HEAD
to refer back to master
, rather than being "detached". Or, if you use git rebase --abort
it will abandon the new chain and just restore your old master
(which you can then re-rebase
later).
(Incidentally, this is one case where graphical tools like gitk
come in handy. Bring up gitk --all
or gitk HEAD master origin/master
on a conflicted rebase and it's often really easy to see where the conflicting commit is.)
For really tough merge cases, there's git-imerge, which I have not used (yet) but looks really nice.
这篇关于要解决合并冲突,我如何看到其他分支所做的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!