如何将 "zealous diff3" 与 git 一起使用?优点和缺点是什么?
How do I use "zealous diff3" with git? And what are the pros and cons?
我刚刚阅读了 release notes for Git 2.35.0(注意 2.35.1 已经可用)。
在那些发行说明中,我看到:
- "Zealous diff3" style of merge conflict presentation has been added.
我的问题:
- 如何使 git diff / difftool 默认为“热心的”差异呈现?
- 在默认差异呈现模式下使用它的优缺点是什么?
新的“zealous diff3”风格是:
merge.conflictStyle = zdiff3
你设置的:
git config --global merge.conflictStyle zdiff3
例如(假设您希望在 per-user 配置中使用它)。
默认样式为merge
:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
(此示例直接来自 the git merge
documentation)。 diff3
样式在中间添加merge base版本,竖线:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
<<<<<<< yours:sample.txt
or cleanly resolved because both sides changed the same way.
Conflict resolution is hard;
let's go shopping.
||||||| base:sample.txt
or cleanly resolved because both sides changed identically.
Conflict resolution is hard.
=======
or cleanly resolved because both sides changed the same way.
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
请注意,为了显示 base 版本与 both branch-tip 版本 之间的差异,行:
or cleanly resolved because both sides changed the same way.
以前 在 <<<<<<< ... >>>>>>>
部分之外(因为它被干净地解决了)现在 在 这个部分。
zdiff3
所做的是采用与 merge
相同的“或完全解决”的路径:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
||||||| base:sample.txt
or cleanly resolved because both sides changed identically.
Conflict resolution is hard.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
这在某种程度上是个谎言,但它是一个有用的谎言。
请注意,如果您愿意,可以采用任何现有的冲突文件,re-create 冲突以新的合并方式出现:
git checkout --conflict=zdiff3 conflicted.txt
(或与 git restore
相同,但我还没有重新训练我的手指)。 小心这个,因为它会覆盖您在合并时所做的任何尝试。
我刚刚阅读了 release notes for Git 2.35.0(注意 2.35.1 已经可用)。
在那些发行说明中,我看到:
- "Zealous diff3" style of merge conflict presentation has been added.
我的问题:
- 如何使 git diff / difftool 默认为“热心的”差异呈现?
- 在默认差异呈现模式下使用它的优缺点是什么?
新的“zealous diff3”风格是:
merge.conflictStyle = zdiff3
你设置的:
git config --global merge.conflictStyle zdiff3
例如(假设您希望在 per-user 配置中使用它)。
默认样式为merge
:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
(此示例直接来自 the git merge
documentation)。 diff3
样式在中间添加merge base版本,竖线:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
<<<<<<< yours:sample.txt
or cleanly resolved because both sides changed the same way.
Conflict resolution is hard;
let's go shopping.
||||||| base:sample.txt
or cleanly resolved because both sides changed identically.
Conflict resolution is hard.
=======
or cleanly resolved because both sides changed the same way.
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
请注意,为了显示 base 版本与 both branch-tip 版本 之间的差异,行:
or cleanly resolved because both sides changed the same way.
以前 在 <<<<<<< ... >>>>>>>
部分之外(因为它被干净地解决了)现在 在 这个部分。
zdiff3
所做的是采用与 merge
相同的“或完全解决”的路径:
Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed,
or cleanly resolved because both sides changed the same way.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
||||||| base:sample.txt
or cleanly resolved because both sides changed identically.
Conflict resolution is hard.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.
这在某种程度上是个谎言,但它是一个有用的谎言。
请注意,如果您愿意,可以采用任何现有的冲突文件,re-create 冲突以新的合并方式出现:
git checkout --conflict=zdiff3 conflicted.txt
(或与 git restore
相同,但我还没有重新训练我的手指)。 小心这个,因为它会覆盖您在合并时所做的任何尝试。