故意创建合并冲突

时间:2015-10-31 17:42:11

标签: merge-conflict-resolution

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

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

1 个答案:

答案 0 :(得分:2)

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

  

当合并之前在同一行或同一文件内容中更改了两个分支时,会发生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/

title credits:Alexander O'Mara