Skip to content

Instantly share code, notes, and snippets.

@lentzi90
Last active February 15, 2020 08:24
Show Gist options
  • Save lentzi90/bb15e9e7e84624e39353890ad082d6e7 to your computer and use it in GitHub Desktop.
Save lentzi90/bb15e9e7e84624e39353890ad082d6e7 to your computer and use it in GitHub Desktop.
Rebase conflict example

Rebase conflict example

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!

  1. Create a new folder and initialize git.
    mkdir rebase-example
    cd rebase-example
    git init
    
  2. 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"
    
  3. 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"
    
  4. 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"
    
  5. 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"
    
  6. Before you have time to merge in your changes, the other branch is merged.
    git checkout master
    git merge fix-plus
    
  7. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment