Resolving Git Merge Conflicts
Git Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file.
Here are some sophisticated tools available in market for visualizing and displaying conflicts those makes life easier.
Some commonly used cost effective tools in market are listed below.
vimdiff,p4merge,sublime merge,diffmerge,semantic merge,beyond compare,code compare,etc
vimdiff:
By default if we are using git bash we can use vimdiff to resolve merge conflicts.
Here I’m listing down all the commands to configure vimdiff for solving conflicts.
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
In below snip we can see i’m resolving merge conflict with vimdiff tool.
Whenever conflict arise during merging use use below command to check difference in vim editor with colors.
git difftool <branch1> <branch2>
Tools used for demo: GitKraken,gitbash
GitKraken: It helps developers become more productive and efficient with Git by graphical view of branches,stages and commits.
Gitbash: It is a tool provides an emulation layer for a Git command line experience.
p4merge tool
One of powerful tool having great debugging capabilities to resolve merge conflicts even for images and videos also.
Here I’m listing out download link and configuration commands for p4merge tool.
Download link: https://www.perforce.com/products/helix-core-apps/merge-diff-tool-p4merge
Commands to configure in gitbash.
git config — global merge.tool p4merge
git config — global difftool.p4merge.path ‘C:\Program Files\Perforce\p4merge.exe’
/* below command is optional command it will take backup of conflict file */
git config — global mergetool.keepBackup false
Showing you simple demo below clearing conflicts using p4merge due to length constraints, I’m not able to capture many things please have a look into below link for better clarity.
Here are some ref’s to handle complex conflicts.