为什么Git无法将文件更改与修改后的父/母合并? [英] Why can't Git merge file changes with a modified parent/master?

查看:84
本文介绍了为什么Git无法将文件更改与修改后的父/母合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,其中只有一行. 我创建一个分支,然后在同一文件中添加第二行.保存并提交到分支. 我切换回主人.并在文件中添加另一行.保存并提交给主服务器. 因此,现在总共有3条唯一的行.

I have a file with one line in it. I create a branch and add a second line to the same file. Save and commit to the branch. I switch back to the master. And add a different, second line to the file. Save and commit to the master. So there's now 3 unique lines in total.

如果我现在尝试将分支合并回主服务器,它将遭受合并冲突.

If I now try and merge the branch back to the master, it suffers a merge conflict.

为什么Git不能简单地将每一行接一个接一个地合并?

Why cant Git simple merge each line, one after the other?

我尝试合并的行为如下:

My attempt at merge behaves something like this:

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

有没有一种方法可以让它自动插入插槽线?

Is there a way to make it slot lines in automatically, one after the other?

推荐答案

假设文件分支A如下:

First line
Branch A's second line

分支B看起来像:

First line
Branch B's second line

合并时,有两种不同的解决方法.这是一种方法:

When you merge, there are two different ways to resolve it. Here's one way:

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不知道您更喜欢这两个选项中的哪一个,或者哪一个甚至是可以接受的合并.

Git has no idea which one of those two options you prefer, or if either are even acceptable merges.

这篇关于为什么Git无法将文件更改与修改后的父/母合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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