Merge Conflicts
Page 8 out of 12
Clarice Bouwer
Software Engineering Team Lead and Director of Cloudsure
Monday, 10 October 2022 · Estimated 1 minute read
You can either use your terminal or a really good GUI merge tool. I use the integrated merge tool inside VS Code.
🤔 If you change a line, and I change the same line differently, which line should Git use? In the snippet below, we have example output of what the conflict information will look like on a particular file.
output
❯ git merge awesome-stuff
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
The merge process is paused as it requires manual intervention to resolve the conflict.
You will notice foreign text in files with conflicts. These are conflict-resolution markers and look something like this:
footer.html
<<<<<<< HEAD:index.html
<div id="footer">contact : email.you@email.dev</div>
=======
<div id="footer">
please contact us at you@email.dev
</div>
>>>>>>> awesome-stuff:index.html
This complicated mambo-jumbo is actually packed with useful information. Let's dissect it:
<<<<<<< HEAD
indicates that the version in HEAD is everything that is above the =======. That means that it is the current change of content that is on the branch that you are on.>>>>>>> awesome-stuff
and everything below ======= is the content from theawesome-stuff
branch. That means that it is the change of content on the incoming branch. (Branch being merged in)index.html
indicates the name of the file where the conflict is happening.- You are expected to remove the chevrons, equal signs and adjust the content to be correct. VS Code tries to help you out so that you don't have to manually change the file. You can either Accept Current Change, Accept Incoming change or Accept Both Changes.
Once you have resolved a merge conflict, you will need to
- save the change
- stage the file
- commit the merge
- push your change