Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Merge branches and Fix conflicts

I have two branches I wanna merge them into each other but the problem is that one of them stopped taking any update from the other months ago. So, when I try to merge them I get a large number of complicated conflicts.

Is there any solution to merge them safely?

Note: I’m using Android Studio

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no way around this…. conflicts happen because code went in different directions and so they have to dealt with. One way you could turn a big pile of conflicts to be dealt with in a single shot could be to rebase the longer branch (since they diverged) onto each one of the commits of the shorter branch. Say…. you have these two branches

A <- B <- C <- D <- E <- (branch1)
     ^
      \- F <- G <- (branch2)

You could run git switch branch2; git rebase C. You might get smaller conflicts, and end up with this:

A <- B <- C <- D <- E <- (branch1)
          ^
           \- F' <- G' <- (branch2)

Then git rebase D, and end up with this:

A <- B <- C <- D <- E <- (branch1)
               ^
                \- F'' <- G'' <- (branch2)

And finally git rebase branch1 and end up with this:

A <- B <- C <- D <- E <- (branch1)
                    ^
                     \- F''' <- G''' <- (branch2)

But this does not mean you will avoid conflicts….. you could actually get more conflicts along the way, but they should theoretically be smaller (that might actually not be the case, but alas, it’s impossible to know beforehand).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading