简体   繁体   English

为什么冲突总是与合并分支有关?

[英]Why the conflicts are always with merging branches?

I'm learning the concepts of Git, I was testing some commands to understand how Git works.我正在学习 Git 的概念,我正在测试一些命令以了解 Git 的工作原理。

I created a remote repository on my Github and cloned it.我在我的 Github 上创建了一个远程存储库并克隆了它。

To test merging between branches ran command:要测试分支之间的合并运行命令:

git checkout -b add_Bob

This line was to create my new branch.这条线是为了创建我的新分支。 Then changed my Bob.txt file, then committed the changes:然后更改了我的 Bob.txt 文件,然后提交了更改:

git checkout master

However, I changed the same line on the same file on the master branch.但是,我在 master 分支的同一个文件上更改了同一行。 I then merged the "add_Bob" branch to my "master branch":然后我将“add_Bob”分支合并到我的“主分支”:

git merge add_Bob

It showed a conflict on the Bob.txt file like this:它显示了 Bob.txt 文件的冲突,如下所示:

Auto-merging Bob.txt
CONFLICT (content): Merge conflict in Bob.txt
Automatic merge failed; fix conflicts and then commit the result.

Why these conflicts are showing?为什么会出现这些冲突?

Merge conflicts happen because you've modified the same line(s) in your branches.发生合并冲突是因为您修改了分支中的同一行。

To fix it open Bob.txt your favorite editor and search for these characters: <<<<<<< HEAD .要修复它打开Bob.txt你最喜欢的编辑器并搜索这些字符: <<<<<<< HEAD ======= divides your changes from the branches which is followed by >>>>>>> name of the branch =======将您的更改与分支分开,然后是>>>>>>> name of the branch

If you want to keep only your branch's changes remove the markers and make the appropriate modification.如果您只想保留分支的更改,请删除标记并进行适当的修改。

After resolving merge conflicts stage and commit your changes.在解决合并冲突阶段并提交您的更改之后。

git add .
git commit -m "commit message" 

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

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