Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Last active July 11, 2018 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simkimsia/3e6ab7f50adf5d889c0323319f0710dd to your computer and use it in GitHub Desktop.
Save simkimsia/3e6ab7f50adf5d889c0323319f0710dd to your computer and use it in GitHub Desktop.
text diagram for git conflicts
              master
                |
                |
   +-------<----+----->------+
   |            |            |
   |            |            |
   |            |            |
branch1         |         branch2
   |            |            |
   |            |            |
   +----->------|            |
                |            |
                |            |
                X-conflict-<-+

Rebase conflicts Assume we start like this where A, B, C etc represents staged changes.

             master
section1        |
   C-------<----A
   |            |         section2
   D            B +----->----F
   |                         |
   E                         G

             master
                |
                A
                |         
                B
                |         rebase-back-to-master
                C------->----C
                |            |
                F            D
                             |
                             E

if rebase rebase-back-to-master into master we get

             master
                |
                A
                |         
                B
                |         rebase-back-to-master
                C------->----C
                |            |
                D            D
                |            |
                E            E
                |
                F

if just plain merge we get

             master
                |
                A
                |         
                B
                |         rebase-back-to-master
                C------>-----C
                |            |
                F            D
                |            |
                G------<-----E
                
where G is like a knot that ties up both branches

remedy is perform 1. pull and rebase at rebase-back-to-master and then 2. resolve conflict at rebase-back-to-master

             master
                |
                A
                |         
                B
                |         rebase-back-to-master
                C------->----C
                |            |
                F            F' 
                             |
                             D
                             |
                             E

After we merge section1 back to master

             master
section1        |
   C-------<----A
   |            |         section2
   D            B +----->----F
   |            |            |
   E            D'           G
                |            
                E'
   

Note!! When you perform a git rebase operation, you're typically moving commits around. So if section1 branch and section2 branch changed same files with respect to the same lines, github pull request will stop you to merge section2 into master branch with rebase since there are conflicts.

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