Skip to content

Instantly share code, notes, and snippets.

@phlbnks
Created November 28, 2019 16:04
Show Gist options
  • Save phlbnks/2e3c7b527c2989614097946feac83492 to your computer and use it in GitHub Desktop.
Save phlbnks/2e3c7b527c2989614097946feac83492 to your computer and use it in GitHub Desktop.
Git merge conflict test generator
#!/bin/bash
# No conflict, changes in branch time order.
mkdir merge-conflict1
cd merge-conflict1
git init
touch test1.sh
git add test1.sh
echo $'Start\nOne\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFour\n\n\n\nEnd' > test1.sh
git commit -am 'initial commit on master test1.sh'
echo $'Start\nInitial\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFinal\n\n\n\nEnd' > test1.sh
git commit -am 'second commit on master test1.sh'
git checkout -b dev
echo $'Start\nFirst\n\n\n\nSecond\n\n\n\nThird\n\n\n\nLast\n\n\n\nEnd' > test1.sh
git commit -am 'first commit on dev test1.sh'
git checkout master
git merge dev
cd -
# Conflict, changes in time but not branch time order.
mkdir merge-conflict2
cd merge-conflict2
git init
touch test2.sh
git add test2.sh
echo $'Start\nOne\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFour\n\n\n\nEnd' > test2.sh
git commit -am 'initial commit on master test2.sh'
git checkout -b dev
git checkout master
echo $'Start\nInitial\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFinal\n\n\n\nEnd' > test2.sh
git commit -am 'second commit on master test2.sh'
git checkout dev
echo $'Start\nFirst\n\n\n\nSecond\n\n\n\nThird\n\n\n\nLast\n\n\n\nEnd' > test2.sh
git commit -am 'first commit on dev test2.sh'
git checkout master
git merge dev
cd -
# Conflict, changes not in time or branch time order.
mkdir merge-conflict3
cd merge-conflict3
git init
touch test3.sh
git add test3.sh
echo $'Start\nOne\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFour\n\n\n\nEnd' > test3.sh
git commit -am 'initial commit on master test3.sh'
git checkout -b dev
echo $'Start\nFirst\n\n\n\nSecond\n\n\n\nThird\n\n\n\nLast\n\n\n\nEnd' > test3.sh
git commit -am 'first commit on dev test3.sh'
git checkout master
echo $'Start\nInitial\n\n\n\nTwo\n\n\n\nThree\n\n\n\nFinal\n\n\n\nEnd' > test3.sh
git commit -am 'second commit on master test3.sh'
git merge dev
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment