Relax, you can’t make it worse
Yes, despite the fear and discomfort we all suffer on this topic, first thing to remember is that you literally can’t make matters worse in Git. As notorious as it can be like a tree conflict in SVN, Git has already taken care of a lot of funky scenarios, leaving you a peace of mind while merging. Also, as a last resort, you always have the choice to undo a merge.
So don’t worry.
How do conflicts happen?
A typical example could be the changes are made to the same part of code in the same file on two branches.
When we try to merge ‘foo’ branch into ‘origin’ branch,
We would receive a lovely message saying ‘CONFLICT’, and the merge should fail miserably.
How to deal with the conflicts?
Supposingly, you can go blame the other people an incompetent dev, or a complete nutcase.
Blame game
Since there is only one in a million chance for merge conflicts to happen, I rather take this as an opportunity to unleash the power of dragon.
Open up the file with conflicts in any editor of your choice, you will see things like:
Now, cleaning up the bits you don’t want is really the matter of patience. What you’ve got left to do is to finish the merge by doing more or less like a normal commit.
And you will actually have both commits from the two branches, and the HEAD is now sitting at the merge commit.
What if I make poo poo in the merge?
As promised, you can undo the merge from the point of merge up to committing the changes, by:
The worst comes to the worst that you want to retract whatever merge is committed, you can still reset the repository to where it was before by: