diff3应该是git上的默认冲突风格吗? [英] Should diff3 be default conflictstyle on git?

查看:180
本文介绍了diff3应该是git上的默认冲突风格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我启用了diff3,现在解决冲突要容易得多。



以前在某些情况下,我必须查看日志以了解人们为什么这样做,做合并。但是对于diff3,信息全部显示在一个地方。

  <<< <<<<< HEAD 
这是有用的
|||||||合并的共同祖先
这是有用的
=======
这真的很有用
>>>>>>> c2392943 .....

由此我们可以很容易地看到结果应该是THIS IS REALLY USEFUL



我在想diff3有什么不好的地方吗?为什么它不是git的默认行为?

解决方案

对于其他读者(和 from this article ): b
$ b


git可以选择以 diff3 格式显示合并冲突(默认情况下,它只显示两个要合并的文件)。你可以像这样启用它:




  git config --global merge.conflictstyle diff3 




真的没有理由不应该启用diff3样式,因为您经常需要祖先来确定正确的合并是什么。


这是,并且我认为它不是默认值,因为默认的unix diff不会显示为3-way diff。




如前所述在这个线程中,如果你想在不设置配置的情况下运行这个命令,这样你就可以轻松地在常规diff和diff3之间切换,这是可能的在一个特定情况下:


如果在索引中标记了冲突(即,您在之后的状态您可以执行以下操作:



  git checkout --conflict = diff3< path ...> 




请注意,这实际上是将索引内容检出到工作树,所以你可能对冲突的工作树副本进行的任何编辑都将被覆盖。



Recently I enabled diff3 and it's much easier to resolve conflict now.

Previously in some cases I had to check the log to see why people did this and that to do the merge. But with diff3 the information is displayed all in one place

<<<<<<< HEAD
THIS IS USEFUL
||||||| merged common ancestors
This is useful
=======
This is really useful
>>>>>>> c2392943.....

From that we can easily see that the result should be "THIS IS REALLY USEFUL"

I wonder if there is any downside to diff3? Why it is not the default behavior of git?

解决方案

For other readers (and from this article):

git has an option to display merge conflicts in diff3 format (by default it only displays the two files to be merged). You can enable it like so:

git config --global merge.conflictstyle diff3

There's really no reason you shouldn't enable the diff3 style, because you frequently need the ancestor to determine what the correct merge is.

This was introduced fairly early (2008), and I supose it isn't the default, because a default unix diff isn't display as a 3-way diff.


As mentioned in this thread, if you want to run this command without setting the config, so that you can switch between normal diffs and diff3s easily, this is possible in one specific case:

If a conflict is marked in the index (i.e., the state you are in after a conflicted merge, but before you mark a path as resolved), you can do:

git checkout --conflict=diff3 <path...>

Note that that is actually checking out the index contents into the working tree, so any edits you may have made to the conflicted working tree copy will be overwritten.

这篇关于diff3应该是git上的默认冲突风格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆