git 的合并冲突解决是否比其他 SCM 和合并工具更有效?

发布于 2024-09-06 23:09:21 字数 718 浏览 5 评论 0原文

git 的合并冲突解决本质上比其他 SCM(CVS、Subversion 等)以及独立的合并工具更有效吗?如果是这样,为什么?

澄清:这里我对算法本身更感兴趣 - 它与普通的 diff3 方法有什么不同吗?
有些工具声称在这方面更聪明(例如 Guiffy),是否值得插入一个作为 git 合并工具? git 在找出文件内或文件间移动的文本片段方面是否更聪明? (而不是报告吵闹的冲突......我从莱纳斯的谈话中对此有一个模糊的印象)。

背景:刚刚使用 git-svn 进行了一次巨大的合并,这导致了比我使用普通 svn merge 得到的冲突一半(第一次合并没有跟踪)..所以我'我想了解为什么。


这些问题/解答类似,但更多的是关于流程的整体情况,以及合并如何更自然地融入其中。为此,git“针对合并进行了优化”(而不是仅分支),它实际上意味着:

  1. 更少的手动冲突 - 更好的自动解决算法(例如,重命名处理得很好)
  2. 更安全操作 - 自动解决留下更多/只留下真正的冲突和更少的错误警报
  3. 更快的操作 - 例如,由于精益和优化意味着对象模型
  4. 更好的工具——这使得体验不那么痛苦,例如基于 DAG 的合并跟踪、mergetool、历史查询/可视化、stash、rebase 等...
  5. 还有
  6. 上述的组合

吗? 现在,我最感兴趣的是 1 & 2.

Is git's merge conflict resolution inherently more efficient than other SCMs (CVS,Subversion,etc.), and also standalone merge tools? If so, why?

Clarification: here I'm more interested in the algorithm itself - is it any different from a plain diff3 method?
Some tools claim to be smarter in that(e.g. Guiffy), is it worth plugging one in as a git merge tool?
Is git any smarter in figuring out pieces of text moved within or across files ? (rather than reporting noisy conflicts.. I had a vague impression of that from Linus' talk).

Background: just did a huge merge using git-svn which resulted in half the conflicts than I got with plain svn merge (first merge with no tracking) .. so I'd like to understand why.


The are similar Qs/As around but they are more about the big picture of the process, and how merging fits in that more naturally. To that end, git being 'optimised for merges' (as opposed to only branching), does it actually mean:

  1. less manual conflicts -- better auto-resolution algorithms (eg. renaming is handled nicely)
  2. safer operation -- auto-resolution leaves more/only real conflicts and less false alerts
  3. faster operation -- say, due to the lean & mean object model
  4. better tooling -- which makes the experience less painful, e.g. DAG-based merge tracking, mergetool, history query/visualisation, stash, rebase,etc...
  5. something else
  6. a combination of the above

?
Now, I'm mostly interested in 1 & 2.

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

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

发布评论

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

评论(2

我很想在这个答案上被证明是错误的,但是……来自于强制性……git 的这个领域还有些欠发达。

  1. git 中不存在自动合并。最新版本具有使用您的更改或他们的更改执行合并的基本支持,但仅此而已。基本上,如果您编辑文件的一部分,而其他人编辑文件的同一部分……您就需要自己进行合并解析。 diff3 格式可用(3 路合并),但我相信统一的 diff 格式是标准。我实际上使用 araxis 作为合并工具,并将其设置为在运行“git mergetool”时使用 3 路合并。不过,来自 perforce...我觉得 git 在这个领域远远落后。

  2. N/A

更新回复:评论

我还没有足够深入地了解 git 认为是冲突的内容以及 p4 认为是冲突的内容,但这是我在两者中所经历的。

  • Git 在进行合并时不会忽略空格...尽管将来会有关于 git 的讨论。 p4 现在可以做到这一点。不忽略空白是一个很大的痛苦,除非团队中的每个人都同意使用空格或制表符,并且如果您想更改文件的缩进......(例如在其他节点周围添加 xml 节点)那么这很快就会过时。
  • 我觉得当我遇到文件中的合并冲突时...... git 说使用其统一差异格式发生冲突的部分更大。当只有一行的一部分发生更改时,它会将较大的部分标记为已修改,并且您需要直观地查找统一差异输出的两个区域之间的更改。不过,您可以使用合并工具来解决这个问题。即使编辑同一行,p4 也能够自动解决冲突。
  • 如果您要合并长期存在的主题分支,那么您将获得真正的享受。如果不打开 rerere(默认情况下关闭),git 会忘记您已经合并了一周前发生冲突的文件,并会要求您再次合并它。 p4 轻松做到这一点

我在这里的答案有点主观......但我非常怀念我与 perforce 的合并。

I would love to be proven wrong on this answer but... coming from perforce... this area of git is a bit under developed.

  1. Auto merging in git is non-existant. The latest version has basic support for performing a merge using your changes or their changes but that's it. Basically if you edit a portion of a file and someone else edits the same portion of a file... you're on your own for merge resolution. The diff3 format is available (3-way merge) but I believe a unified diff format is the standard. I actually use araxis as the merge tool and have it setup to use 3 way merge when running "git mergetool". Coming from perforce though... I feel like git is way behind in this area.

  2. N/A

Update RE: comments

I haven't dug deep enough into exactly what git thinks is a conflict and exactly what p4 thinks is a conflict but here's what I've experienced in both.

  • Git does not ignore white space when doing a merge... although there is talk about this in the future for git. p4 can do this now. Not ignoring white space is a major pain unless everyone on the team agrees on using spaces or tabs and if you'd like to change the indention of a file... (e.g. adding an xml node around other nodes) then this gets old fast.
  • I feel like when I come across merge conflicts in a file... the parts that git says are in conflict using it's unified diff format are larger. When it's only a portion of one line that's changed it will mark larger portions as modified and you need to visually hunt down the changes between the two areas of of the unified diff output. You can kind of get around this using a mergetool though. p4 is able to auto resolve conflicts even if editing the same line.
  • If you're merging long lived topic branches then you're in for a real treat. Without rerere turned on (which is off by default) git will forget that you've already merged that file that was in conflict a week ago and will ask you to merge it again. p4 does this with ease

My answers here are a bit subjective... but I do sorely miss the merging that I had with perforce.

我很OK 2024-09-13 23:09:21

此外,这个更新thread (2012) 详细介绍了 Git 的“自动解析”概念:

我对“自动解决”的定义:
“在合并期间,工作树文件会更新以反映合并的结果......当双方对同一文件的不同区域进行更改时,git 会选择双方
自动,并由您来确保在 git 进行合并提交后检查这些合并结果的正确性。”

IOW,“自动解决”具体意味着双方(我们的和他们的)自 file(a)< 的共同祖先版本以来对 file(a) 进行了更改/code>,并且 git 选择了双方,而没有引发合并冲突。
(我提出“自动解决”一词的原因是因为在 git-merge 输出中,术语“自动合并”也可以表明只有一侧(他们的)更改了file(a) 自共同祖先以来,git 只是在共同祖先 file(a) 之上“快进”他们的 file(a)代码>.)


Junio C Hamano 在回答中提出了一个重要的观点:

  • 知道git很愚蠢,而且为了安全起见会犯错,把任何复杂的事情都抛在一边;
  • 知道同一文件中发生的文本非冲突在不同文件之间具有相同的语义冲突风险,因此单独列出“触及同一文件但没有冲突”任何特殊内容是毫无意义的,但无论哪种情况,发生这种冲突的可能性很小,因此首先完成合并(和其他合并)然后检查总体结果可以更有效地利用您的时间,因为无论如何在推出结果之前您都必须至少观察一次结果。

5 年半后,2018 年 5 月更新(Git 2.18,2018 年第 2 季度)

git mergetools”学会了与 guiffy 交谈

请参阅 提交 6ceb658(2018 年 4 月 5 日),作者:比尔·里彻 (``)
(由 Junio C Hamano -- gitster -- 合并于 提交da36be5,2018年4月25日)

mergetools:添加对 guiffy 的支持

添加guiffy作为difftoolmergetool

guiffy 可在 Windows、Linux 和 MacOS 上使用

In addition, this more recent thread (2012) details the notion of "auto-resolution" with Git:

My definition for "auto-resolve":
"During a merge, the working tree files are updated to reflect the result of the merge... When both sides made changes to different areas of the same file, git picks both sides
automatically, and leaves its up to you to make sure you review those merge results for correctness after git has made the merge commit."

IOW, an "auto-resolve" specifically means that both sides (ours and theirs) made changes to file(a) since the common-ancestor version of file(a), and git picked both sides without raising a merge-conflict.
(The reason I came up with the term "auto-resolve" is because in the git-merge output the term "Auto-merging" can also indicate that only one side (theirs) changed file(a) since the common-ancestor and that git is just "fast-forwarding" theirs file(a) on top of common-ancestor file(a).)

Junio C Hamano raises in answer an important point:

  • know git is stupid and errs on the safe side, punting anything remotely complex;
  • know that textual non-conflicts that occur in the same file have the same risk of having semantic conflict across different files, so singling out "touched the same file but did not conflict" any special is pointless, but in either case, the chance of having such a conflict is small enough that completing the merge (and other merges) first and then checking the overall result is more efficient use of your time, because you have to eyeball the result at least once anyway before pushing it out.

Update 5 and a half years later, May 2018 (Git 2.18, Q2 2018)

"git mergetools" learned talking to guiffy.

See commit 6ceb658 (05 Apr 2018) by Bill Ritcher (``).
(Merged by Junio C Hamano -- gitster -- in commit da36be5, 25 Apr 2018)

mergetools: add support for guiffy

Add guiffy as difftool and mergetool.

guiffy is available on Windows, Linux, and MacOS

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