简体   繁体   English

Git如何插入其他共同祖先进行合并

[英]Git how to insert a different common ancestor for merge

I am trying to merge two different branches in Git like this: 我试图像这样合并Git中的两个不同的分支:

                         [Mod 1 binary] - [Mod 1 Text]
                    /                                 \
[Original(Binary)]                                      [CombinedText]   
                    \                                 /
                         [Mod 2 Binary] - [Mod 2 Text]

The problem is that the merge tool I am using can only handle text files so the binary file does not work as a common ancestor. 问题是我使用的合并工具只能处理文本文件,因此二进制文件不能作为公共祖先工作。 I want to make a text file from the original binary file with a conversion tool ant then have a structure like this so I can merge: 我想使用转换工具ant从原始二进制文件制作文本文件,然后使用这样的结构以便合并:

                                     [Mod 1 Text]
                                   /               \
[OriginalBinary] - [Original Text]                    [Combined Text]
                                   \                /
                                     [Mod 2 Text]

How can I accomplish this? 我该怎么做?

Sounds like you should do exactly what you said: "commit on a new branch". 听起来您应该按照您所说的去做:“提交到新分支”。 In a shell-based session your task might go like this: 在基于shell的会话中,您的任务可能如下所示:

$ git checkout -b work-br <commit-id>

(here <commit-id> is the ID of the commit containing OriginalBinary ), then: (这里<commit-id>是包含OriginalBinary的提交的ID),然后:

$ tool_cmd [options] binary [> text]  # or however this works
$ git add text
$ git commit

You now have: 您现在拥有:

    B - C        <-- branch-1
  /
A
 \\
 |  D - E        <-- branch-2
 |
 |
  \
    F            <-- work-br

where commit A has only the original binary, B has Mod1 Binary , C has Mod1 Text , D has Mod2 Binary , and E has Mod2 Text . 其中提交A仅具有原始二进制文件, B具有Mod1 BinaryC具有Mod1 TextD具有Mod2 BinaryE具有Mod2 Text New commit F has both the original binary and the text-ified version. 新的提交F具有原始二进制文件和文本化版本。

At this point you can make two (or just one, really) more branch and then git cherry-pick commit C into one of the two new branches, switch to the other branch, git chery-pick commit E into the other, and have this graph fragment: 此时,您可以再增加两个(或实际上只有一个)分支,然后将git cherry-pick提交C到两个新分支之一,切换到另一个分支,将git chery-pick提交E到另一个分支,并该图片段:

    B - C        <-- branch-1
  /
A
 \\
 |  D - E        <-- branch-2
 |
 |      C'       <-- work-branch-1
  \   /
    F
      \
        E'       <-- work-branch-2

Now you can merge the text files (ignoring or even removing the binary files if need be) to get a merged result, which you can then import back to whichever original branch you want, or even just use directly from this new set of branches. 现在,您可以合并文本文件(如果需要,可以忽略甚至删除二进制文件)以获取合并结果,然后可以将其导入回想要的任何原始分支,甚至可以直接从这组新分支中使用。

After

$git replace --graft hash([Mod 1 Text]) hash([Original text])
$git replace --graft hash([Mod 2 Text]) hash([Original text])

git will merge both [Mod 1 Text] [Mod 2 Text] as if [Original text] is their common parent. git将[Mod 1 Text] [Mod 2 Text]合并,就好像[Original text]是它们的共同父代一样。 You can later remove the replacement with git replace -d hash([Mod 1 Text]) hash([Mod 2 Text]) if you feel like. 您以后可以根据需要使用git replace -d hash([Mod 1 Text]) hash([Mod 2 Text])删除替换项。

See https://git-scm.com/docs/git-replace for details. 有关详细信息,请参见https://git-scm.com/docs/git-replace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM