git - 为什么 merge 需要您考虑共同的祖先?

标签 git diff three-way-merge

我正在学习 Git,并在 this site 上找到教程很有用。在该页面上,关于 merge ,它包括:

         +---------- (D) ---------------+
        /             |                  \
(A) -- (B) -- (C) -------------- (E) -- (F)
                      |                  |
                 fix-headers           master
                                         |
                                        HEAD

The merge commit is (F), having parents (D) and (E). Because (B) is the common ancestor between (D) and (E), the files in (F) should contain the changes between (B) and (D), namely the heading fixes, incorporated into the files from (E).

我不明白为什么你会担心共同的祖先B。为什么你不能直接 merge D和E产生F? D 将派生自 B 但可能包含您想要的差异。 B 和 D 之间可能有许多提交,进行了更改并删除了更改。

最佳答案

(我犹豫要问这是不是愚人节,我不想侮辱任何人...)

也许你不明白这是 git 你做的 merge ?

问题:这是D和E,你能告诉我F应该是什么样子吗?

D                                        E
using System;                            using System;
public void main()                       public void main()
{                                        {
     Console.WriteLine("hello world");        Console.WriteLine("Hello world!");
}                                        }

回答:不,你不能

但是,如果你知道 B 长这样:

B
using System;
public void main()
{
     Console.WriteLine("hello world");
}

这变得很简单,git 可以自行处理

不知道这是否回答了您的问题...

关于git - 为什么 merge 需要您考虑共同的祖先?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5513132/

相关文章:

svn - 从两个日期之间的 svn 命令行获取更改的文件

git - 撤消分支 merge

python - 如何在 Python 脚本中 stash 个人数据

java - 如何监视文件中的新内容并检索该内容

git - 从命令行在 sublime 中打开 git diff

git - 解决 IDE 中的 merge 冲突,同时保留 3 向 merge 信息

javascript - Javascript 中数组的三向比较函数

python - python中的三向字典深度合并

git - 直接从 git shell 添加文件到 .gitignore

Git/gerrit,远程推送被拒绝,未做任何更改