如何使用“zealous diff3”用吉特?有什么优点和缺点?

发布于 2025-01-09 15:12:39 字数 375 浏览 3 评论 0原文

我刚刚阅读了 Git 2.35.0 的发行说明 (注意 2.35.1 已经可用)。

在这些发行说明中,我看到:

  • 添加了“Zealous diff3”风格的合并冲突呈现。

我的问题:

  1. 如何使 git diff / difftool 默认为“热心”差异演示文稿?
  2. 与默认的差异呈现模式相比,使用它有哪些优点和缺点?

I just read the release notes for Git 2.35.0 (note 2.35.1 is already available though).

In those release notes, I saw that:

  • "Zealous diff3" style of merge conflict presentation has been added.

My questions:

  1. How do I make git diff / difftool default to "zealous " diff presentation?
  2. What are the pros and cons of using it over the default diff presentation mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2025-01-16 15:12:39

新的“zealous diff3”样式是:

merge.conflictStyle = zdiff3

您可以设置它

git config --global merge.conflictStyle 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.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.

此示例直接来自 git merge 文档)。 diff3 样式在中间添加了合并基础版本,并带有竖线:

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 版本和两个分支提示之间的差异版本,该行:

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.

这在某种程度上是一个谎言,但它有用说谎。

请注意,如果您愿意,您可以获取任何现有的冲突文件,并以新的合并样式重新创建冲突:(

git checkout --conflict=zdiff3 conflicted.txt

或与 git Restore 相同,但我还没有重新训练我的手指

The new "zealous diff3" style is:

merge.conflictStyle = zdiff3

which you'd set with:

git config --global merge.conflictStyle zdiff3

for instance (assuming you want this in your per-user configuration).

The default style is 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.

(this example is straight from the git merge documentation). The diff3 style adds the merge base version in the middle, with vertical bars:

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.

Note that in order to show the difference between the base version and both branch-tip versions, the line:

or cleanly resolved because both sides changed the same way.

which used to be outside the <<<<<<< ... >>>>>>> section (because it was cleanly resolved) is now inside this section.

What zdiff3 does is take the same "or cleanly resolved" path that merge takes:

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.

This is a lie, of sorts, but it's a useful lie.

Note that if you'd like, you can take any existing conflicted file and re-create the conflict in a new merge style:

git checkout --conflict=zdiff3 conflicted.txt

(or the same with git restore but I haven't retrained my fingers yet ????). Be careful with this as it overwrites any attempt you've made at merging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文