When rebasing instead of merging, you may run into "strange" conflicts where you get the "same" conflict again and again. This is an attempt to explain one reason why you may run into this and how to properly solve them.
The code we are starting out with looks like this:
one + on eqvals three
The goal is to fix it so that it looks like this, while learning some git:
one plus one equals two
Let's get started!
- Create a new folder and initialize git.
mkdir rebase-example cd rebase-example git init
- Create the initial commit with the initial code.
cat <<EOF > code.txt one + on eqvals three EOF git add code.txt git commit -m "Initial commit"
- Start working on your own branch for fixing the last three words.
git checkout -b fix-last-part # Fix the first spelling mistake (on -> one) sed -i "s/on /one /g" code.txt git add code.txt git commit -m "Fix typo one"
- In parallel to your work in step 3, someone else fixes the "+".
git checkout master git checkout -b fix-plus sed -i "s/+/plus/g" code.txt git add code.txt git commit -m "Fix plus"
- You continue your work on the last few words.
git checkout fix-last-part sed -i "s/eqvals/equals/g" code.txt git add code.txt git commit -m "Fixed typo equals" sed -i "s/three/two/g" code.txt git add code.txt git commit -m "Fix calculation mistake"
- Before you have time to merge in your changes, the other branch is merged.
git checkout master git merge fix-plus
- For whatever reason (not saying it is right or wrong) you decide to rebase on master.
git checkout fix-last-part git rebase master
And of course you get a conflict! Let's take a look at what is really going on here.
WIP