25 | Handling Conflicts with a GUI |
Merging is often made easier with a GUI that displays each version of the code in question and allows you to choose which version you prefer. You can use git mergetool to launch a GUI tool to handle merge conflicts.
You can choose from several different merge tools. Their availability varies between platforms, and how you interact with a tool is slightly different for each one you use for merging. Generally, the local copy (the original that was in your branch before the merge) is displayed on the left, with the remote, new code on the right.
Common to all GUI merge tools is the ability to step through each change and choose which version you like. You must save those changes before exiting. git mergetool looks at the result and stages that as the correct version of the conflicting code.
You have to commit your changes once the conflict has been resolved, just like manually merging the conflicts (see Task 24, Handling Conflicts). git mergetool stages the changes for you; that’s the only difference.
What To Do... |
| prompt> git mergetool |
| merge tool candidates: opendiff kdiff3 tkdiff xxdiff meld |
| tortoisemerge gvimdiff diffuse ecmerge p4merge araxis emerge vimdiff |
| Merging the files: dolt.py |
| |
| Normal merge conflict for 'dolt.py': |
| {local}: modified |
| {remote}: modified |
| Hit return to start merge resolution tool (opendiff): |
| prompt> git config --global merge.tool "gvimdiff" |
This example shows the Window-specific command, but you can use the same process on any platform for a custom merge tool.
| prompt> git config --global merge.tool p4merge |
| prompt> git config --global mergetool.p4merge.cmd |
| 'p4merge.exe "$BASE" "$LOCAL" "$REMOTE" "$MERGED"' |
Task 15, Merging Commits Between Branches
Task 24, Handling Conflicts
3.128.226.255