有意制造合并冲突

12

我已经从GitHub上拉取了文件。现在我需要创建一个合并冲突。

如何在GitHub上故意创建合并冲突?


2
在两个分支中编辑同一行,然后尝试合并。 - Alexander O'Mara
1个回答

7

在两个分支中编辑相同的行,尝试合并

当两个分支在合并之前更改了同一行或文件的相同内容时,git会出现合并冲突。如果你只是扩展了一个文件或附加了一些内容,git通常可以自动解决。

使用以下代码:

#!/bin/bash
mkdir git-repo
cd git-repo
git init
touch my_code.sh
git add my_code.sh
echo "echo Hello" > my_code.sh
git commit -am 'initial'
git checkout -b new_branch
echo "echo \"Hello World\"" > my_code.sh
git commit -am 'first commit on new_branch'
git checkout master
echo "echo \"Hello World!\"" > my_code.sh
git commit -am 'second commit on master'
git merge new_branch

脚本来源: https://jonathanmh.com/how-to-create-a-git-merge-conflict/

标题制作: Alexander O'Mara


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接