git diff看看合并会带来什么

Tec*_*eer 4 git version-control merge git-merge

所以我和一个朋友一直在做一个项目。大多数时候合并很容易,因为我们通常在不同的领域工作。

最近,我们已经越来越多地彼此碰撞,创建令人讨厌的合并(最后期限)。

因此,我们开始研究查看合并的方式。我找到了一种使用git diff的方法:

git diff mybranch...hisbranch
Run Code Online (Sandbox Code Playgroud)

这给出了很好的结果。问题是,因为它使用了最后一个共同祖先,并且祖先越来越远,所以合并中有很多垃圾在我们两个分支中都没有更改。

所以我想知道是否有一种方法可以准确地可视化合并将执行的操作。

我试过了:

git diff $(git-merge mybranch hisbranch) hisbranch
Run Code Online (Sandbox Code Playgroud)

这似乎工作正常,但是我想以另一种方式可视化合并,所以我尝试了:

git diff $(git-merge hisbranch mybranch) mybranch
Run Code Online (Sandbox Code Playgroud)

但是在这种情况下 git-merge: command not found

有谁知道一个很好的方法来获得两个分支的差异,以显示合并会引入什么?也许突出冲突?

如果没有,是否有任何可视化工具将允许您手动进行提交,因此可以选择最佳的代码版本。

Chr*_*her 6

还有其他可视化方式,但是我发现最简单的方法是git merge --no-commit。从手册页:

--commit, --no-commit
Perform the merge and commit the result. This option can be used to override --no-commit.

With --no-commit perform the merge but pretend the merge failed and do not autocommit, to give the user a chance to inspect and further tweak the merge
result before committing.
Run Code Online (Sandbox Code Playgroud)

基本上,我只是发布git merge --no-commit <branch>并检查结果。如果我不喜欢它们,我发布git merge --abort,或者如果我想提交合并,我通常会继续进行git commit