git在递归合并中选择简单的基础 [英] git choose simpler base in recursive merge

查看:121
本文介绍了git在递归合并中选择简单的基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在分支之间合并时,git会执行带有冲突的递归合并,将<<<<<<<<<临时合并分支x 块。这有点令人讨厌,导致需要手动干预kdiff3的25个冲突。

然后我做了一个git merge-base,它只返回一个SHA1(参见我的其他问题,如果你能帮助我理解为什么)。



如果我使用该提交的代码作为基础手动构建kdiff3中的3-way合并,它会更加简单,只需2个直接的冲突即可手动解决。

b
$ b

有没有什么办法可以用标准的git命令做到这一点,而不必手动为文件建立自己的合并?

解决方案

[从另一个问题移回,现在这个问题回来了:-) ...我只留下一个链接,而不是完全删除这个答案。]



它有点klunky,但你可以运行 git merge-file 命令手动提取所需的基本,本地和其他文件版本后。这给了你最大的控制权,我认为如果Git提供了一个小帮手程序来运行它可能会很好。



git checkout



也就是说,我们应该可以这样做:

  git merge --no-commit< args> 

然后不管我们得到什么状态,包括像递归合并这样的icky情况,虚拟合并基础作为索引中的通用基础,我们应该可以这样做:

  git re-merge [options] <路径> 

默认情况下会从当前索引中提取base,local和other,并重新尝试合并。



这个默认值和 git checkout -m - < path> 完全一样,那么为什么会这个提议的帮手是否有用?那么:
$ b


  1. 请注意, git checkout 也可以做 - 我们的(使用本地解析)和 - 他们的(使用其他解析)。这个建议的命令会有 - 我们的 s / - 本地 - 他们的 / - 其他,这会提取这些版本,但不像 git checkout



    这里的想法是,在冲突尚未标记为已解决的情况下,您可以查看 git diff 输出方便。


  2. 它会有 - union c $ c> git merge-file 也有但是 git checkout 不)。联合合并很少用,但在 的罕见情况下,它确实很适合让计算机执行此操作。


  3. 以下是这种特殊情况下的关键项目:它将有一些方法来指定基地。例如, - base< tree-ish> [--basepath< path>] 会忽略索引的基blob,并从给定的< tree-ish> 取基。默认的< path> 将与当前目录中的文件相同,因此我们需要一种解决重命名情况的方法。这就是 - basepath 会做的事,或者< tree-ish> 可能只是< tree-ish-blob> ,以便 - base HEAD〜15:path / to / different / name 起作用。

  4. C $ C>。它的主要优点是允许您不必知道如何从索引中提取斑点,创建一堆临时文件,然后清理这些临时文件。此外,因为它永远不会解决任何问题(不像 git checkout ),它感觉不到最终的结果,或者至少对我来说是这样。


    When I merge between branches, git does a recursive merge with conflicts, putting in <<<<<<< Temporary merge branch x blocks. It's a bit nasty, resulting in 25 conflicts requiring manual intervention in kdiff3.

    I then do a git merge-base, which returns just a single SHA1 (see my other question if you could help me understand why).

    If I manually build up a 3-way merge in kdiff3 using the code from that commit as the base, it's much simpler, with only 2 straightforward conflicts to manually resolve.

    Is there any way I can do this with standard git commands, rather than having to manually build up my own merge for the file?

    解决方案

    [Moved back from the other question, now that this question is back :-) ... and I'll leave just a link there rather than deleting that answer entirely.]

    It's somewhat klunky, but you can run the git merge-file command after manually extracting the desired base, local, and other file-versions. This gives you the most control, and I think it might be nice if Git provided a small helper program to run it.

    There is git checkout -m, but see below.

    That is, we should be able to do:

    git merge --no-commit <args>
    

    and then regardless of what state we get, including icky cases like the recursive merge that have installed a "virtual merge base" as the common base in the index, we should be able to do:

    git re-merge [options] <path>
    

    which by default would extract base, local, and other from the current index and re-attempt the merge.

    This default is exactly the same as git checkout -m -- <path>, so why would this proposed helper be any use? Well:

    1. Note that git checkout can also do --ours (resolve using local) and --theirs (resolve using other). This proposed command would have --ours/--local and --theirs/--other, which would extract those versions but unlike git checkout, not mark the conflict resolved.

      The idea here is that with the conflict not yet marked resolved, you can view git diff output conveniently.

    2. It would have --union (which git merge-file also has but git checkout does not). Union merge is rarely useful, but in those rare cases when it is useful, it sure would be nice to have the computer do it.

    3. Here's the key item for this particular case: It would have some way to specify the base. For instance, --base <tree-ish> [--basepath <path>] would disregard the index's base blob and take the base from the given <tree-ish>. The default <path> would be the same as the file in the current directory, so we need a way to address rename cases. This is what --basepath would do, or perhaps <tree-ish> could just be <tree-ish-or-blob> so that --base HEAD~15:path/to/different/name works.

    This is, again, just a minor wrapper around git merge-file. Its chief virtue is allowing you not to have to know how to extract blobs from the index, make a bunch of temporary files, and then clean up those temporary files. Also, because it never resolves anything (unlike git checkout), it "feels less final", or at least it does to me.

    这篇关于git在递归合并中选择简单的基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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