Git 为什么可以';是否使用修改的父/母文件合并文件更改?

Git 为什么可以';是否使用修改的父/母文件合并文件更改?,git,Git,我有一个文件,里面有一行。 我创建了一个分支,并在同一个文件中添加了第二行。保存并提交到分支。 我转回到主人那里。并在文件中添加另一行。保存并提交给主机。 现在总共有3条独特的线路 如果我现在尝试将分支合并回主分支,它将遇到合并冲突 为什么Git simple不能一行接一行地合并每一行 我尝试合并的行为如下所示: PS D:\dev\testing\test1> git merge newbranch Auto-merging hello.txt CONFLICT (content): M

我有一个文件,里面有一行。 我创建了一个分支,并在同一个文件中添加了第二行。保存并提交到分支。 我转回到主人那里。并在文件中添加另一行。保存并提交给主机。 现在总共有3条独特的线路

如果我现在尝试将分支合并回主分支,它将遇到合并冲突

为什么Git simple不能一行接一行地合并每一行

我尝试合并的行为如下所示:

PS D:\dev\testing\test1> git merge newbranch
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
PS D:\dev\testing\test1> git diff
diff --cc hello.txt
index 726eeaf,e48d31a..0000000
--- a/hello.txt
+++ b/hello.txt
@@@ -1,2 -1,2 +1,6 @@@
  This is the first line.
- New line added by master.
 -Added a line in newbranch.
++<<<<<<< HEAD
++New line added by master.
++=======
++Added a line in newbranch.
++>>>>>>> newbranch
PS D:\dev\testing\test1>git merge newbranch
自动合并hello.txt
冲突(内容):在hello.txt中合并冲突
自动合并失败;修复冲突,然后提交结果。
PS D:\dev\testing\test1>git diff
diff--cc hello.txt
索引726eeaf,e48d31a..0000000
---a/hello.txt
+++b/hello.txt
@@@ -1,2 -1,2 +1,6 @@@
这是第一行。
-主添加的新行。
-在newbranch增加了一条线。
++>新牧场

有没有办法让它一行接一行地自动插入行?

我可以告诉你为什么它不能合并这两行-根据git的说法,FileA的第2行是“某某”,而FileB的第2行是“其他”。因此,根据git的说法,它试图从FileA和FileB创建一个文件,其中一行有两个可能的值。它无法决定您想要哪一个,因此它会同时转储它们并让您修复它。

假设文件分支A看起来像:

First line
Branch A's second line
First line
Branch B's second line
分支B看起来像:

First line
Branch A's second line
First line
Branch B's second line
合并时,有两种不同的方法来解决它。这里有一个方法:

First line
Branch A's second line
Branch B's second line
还有一种方法:

First line
Branch B's second line
Branch A's second line

Git不知道您更喜欢这两个选项中的哪一个,或者哪一个是可以接受的合并。

假设您有这样一行:

printf(something);
在布兰卡,你可以做到:

while(x < 5)
printf(something);
if(y>10)
printf(something);

您如何合并它,或者更确切地说,您是否信任工具为此创建的合并结果?

有一个名为
union
的git合并策略,可以从
.gittributes
配置文件中为您配置该策略,但是,您将无法控制冲突行在合并文件中结束的顺序,也无法使用冲突标记来指示发生冲突的位置


您还可以定义一个自定义合并策略,该策略可以使用有关文件结构的一些专门知识来确定正确的顺序。

似乎没有简单的方法来确定文件的开槽顺序-毕竟,对于可执行代码来说,顺序当然很重要。