为什么会出现合并冲突? [英] Why do I get a merge conflict?

查看:240
本文介绍了为什么会出现合并冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将最新版本的Git下载到我的Windows平台上.我有一个提交了以下内容的文件:

I just downloaded the most recent version of Git to my Windows platform. I have a file with the following content committed:


Line 1
Line 2
Line 3
Line 4

然后我创建一个分支,其中包括: git分支开发
我继续在 master 分支上并修改第一行,这样我现在有了:

I then create a branch with: git branch development
I continue on the master branch and modify the first line so I now have:


Line 1master
Line 2
Line 3
Line 4

我在 master 分支上暂存并提交更改.我切换到 development 分支并修改第二行,这样我现在有了:

I stage and commit the change on the master branch. I switch to the development branch and modify the second line so I now have:


Line 1
Line 2development
Line 3
Line 4

我在 development 分支上暂存并提交更改.现在,我切换回 master 分支.我尝试将开发分支与:
git合并开发
我遇到以下冲突:

I stage and commit the change on the development branch. I now switch back to the master branch. I attempt to merge the development branch with:
git merge development
I get the following conflict:


<<<<<<<< HEAD
Line 1master
Line 2
=======
Line 1
Line 2development
>>>>>>> development
Line 3
Line 4

但是为什么呢?创建分支之后,对主分支和开发分支分别进行了更改.但是它们位于文件中的不同行.那么为什么要发生冲突呢?

But why? After the branch was created, a change was made each on the master and development branches. But they were to different lines in the file. So why a conflict?

推荐答案

之所以会发生冲突,是因为您在提交对master的更改之前先创建了开发分支,因此master在以下位置具有不同的内容(line1master)当您尝试合并开发分支时.

You get the conflict because you made the development branch before commiting the changes on master, so master has different content (line1master) at the moment you try to merge the development branch.

此图更好地说明了这种情况;

this image illustrates better the case;

这篇关于为什么会出现合并冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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