Skip to content
Fix Code Error

How to resolve merge conflicts in Git repository?

March 13, 2021 by Code Error
Posted By: Spoike

I want to resolve merge conflicts in my Git repository.

How to do that ?

Solution

Try: git mergetool

It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it’s enough by itself. It is much better than doing the whole thing by hand certainly.

As per @JoshGlover comment:

The command

doesn’t necessarily open a GUI unless you install one. Running git mergetool for me resulted in vimdiff being used. You can install
one of the following tools to use it instead: meld, opendiff,
kdiff3, tkdiff, xxdiff, tortoisemerge, gvimdiff, diffuse,
ecmerge, p4merge, araxis, vimdiff, emerge.

Below is the sample procedure to use vimdiff for resolve merge conflicts. Based on this link

Step 1: Run following commands in your terminal

git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false

This will set vimdiff as the default merge tool.

Step 2: Run following command in terminal

git mergetool

Step 3: You will see a vimdiff display in following format

  ╔═══════╦══════╦════════╗
  ║       ║      ║        ║
  ║ LOCAL ║ BASE ║ REMOTE ║
  ║       ║      ║        ║
  ╠═══════╩══════╩════════╣
  ║                       ║
  ║        MERGED         ║
  ║                       ║
  ╚═══════════════════════╝

These 4 views are

LOCAL – this is file from the current branch

BASE – common ancestor, how file looked before both changes

REMOTE – file you are merging into your branch

MERGED – merge result, this is what gets saved in the repo

You can navigate among these views using ctrl+w. You can directly reach MERGED view using ctrl+w followed by j.

More info about vimdiff navigation here and here

Step 4. You could edit the MERGED view the following way

If you want to get changes from REMOTE

:diffg RE  

If you want to get changes from BASE

:diffg BA  

If you want to get changes from LOCAL

:diffg LO 

Step 5. Save, Exit, Commit and Clean up

:wqa save and exit from vi

git commit -m "message"

git clean Remove extra files (e.g. *.orig) created by diff tool.

Answered By: Peter Burns

Related Articles

  • Setting up and using Meld as your git difftool and mergetool
  • Recalculate merge conflicts (ie. how to generate…
  • Viewing all `git diffs` with vimdiff
  • Git merge with force overwrite
  • What are the new features in C++17?
  • Why do I have to "git push --set-upstream origin "?
  • Git workflow and rebase vs merge questions
  • Gradle error: Execution failed for task…
  • What is your most productive shortcut with Vim?
  • Why does C++ code for testing the Collatz conjecture…
  • Why does git say "Pull is not possible because you…
  • Why do git fetch origin and git fetch : behave differently?
  • Git Using Remote Branch
  • Checkout another branch when there are uncommitted…
  • How to recover stashed uncommitted changes
  • How to set Meld as git mergetool
  • How to track untracked content?
  • Git: How configure KDiff3 as merge tool and diff tool
  • Use of Jquery on scroll event
  • git pull while not in a git directory
  • org.gradle.api.tasks.TaskExecutionException:…
  • Logging best practices
  • How can I find the product GUID of an installed MSI setup?
  • Why call git branch --unset-upstream to fixup?
  • Git - Pushing code to two remotes
  • In plain English, what does "git reset" do?
  • git stash blunder: git stash pop and ended up with…
  • How do I make a Git commit in the past?
  • getting error while updating Composer
  • The definitive guide to form-based website authentication
  • What's the difference between HEAD^ and HEAD~ in Git?
  • How do I deal with installing peer dependencies in…
  • Ember Data. Save model with "belongsTo" relationship
  • Git Cherry-pick vs Merge Workflow
  • Git stash pop- needs merge, unable to refresh index
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Git mergetool generates unwanted .orig files
  • What exactly classNameBindings is doing?
  • Retrieve specific commit from a remote Git repository
  • What is "git remote add ..." and "git push origin master"?
  • Resolving tree conflict
  • Maximum XOR With an Element From Array | Leetcode
  • Format Column Data before passing to Vue Good-Table
  • git rebase merge conflict
  • Pandas Merging 101
  • git lfs push to github failure on Ubuntu 18.04
  • failed to push some refs to [email protected]
  • How do I 'overwrite', rather than 'merge', a branch…
  • Memcached vs. Redis?
  • Why does Git say my master branch is "already up to…
  • How to pull in changes from skeleton sub-repository…
  • Overriding .fetch() works with fake data, errors…
  • Improve INSERT-per-second performance of SQLite
  • How to paste yanked text into the Vim command line
  • Why does git perform fast-forward merges by default?
  • TypeError: Cannot read property 'webpackJsonp' of undefined
  • Various ways to remove local Git changes
  • Set up adb on Mac OS X
  • How can I find the location of origin/master in git,…
  • What exactly does the "u" do? "git push -u origin…
  • Start redis-server with config file
  • WAMP server, localhost is not working
  • Polymer: Data binding breaking with on-tap handler…
  • How to expand/collapse a diff sections in Vimdiff?
  • Show Console in Windows Application?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Your configuration specifies to merge with the from…
  • Simple tool to 'accept theirs' or 'accept mine' on a…
  • In Visual Studio Code How do I merge between two…
  • Identifying and solving…
  • Homebrew install specific version of formula?
  • Database development mistakes made by application developers
  • how does git know there is a conflict
  • Why is Git better than Subversion?
  • SVN how to resolve new tree conflicts when file is…
  • ExpressJS How to structure an application?
  • How do I install Java on Mac OSX allowing version switching?
  • What's the best way of scraping data from a website?
  • git switch branch without discarding local changes
  • Chrome DevTools Devices does not detect device when…
  • Does "git fetch --tags" include "git fetch"?
  • Git on Windows: How do you set up a mergetool?
  • Push on GIT and Bitbucket
  • How to backup a local Git repository?
  • Configuring diff tool with .gitconfig
  • How to commit my current changes to a different…
  • cordova Android requirements failed: "Could not find…
  • How to clone ('fork') your own personal GitHub repo…
  • Practical uses of git reset --soft?
  • Smart way to truncate long strings
  • How to upload a project to Github
  • Merge, update, and pull Git branches without using checkouts
  • Git push error: "origin does not appear to be a git…
  • Git merge master into feature branch
  • What are the undocumented features and limitations…
  • Is it possible to use pip to install a package from…
  • Best way to replace multiple characters in a string?
  • How to UPSERT (MERGE, INSERT ... ON DUPLICATE…
  • How do I clone a single branch in Git?
  • Rendering nested list with v-for and vue components

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Deleting an element from an array in PHP

Next Post:

How to remove an element from a list by index

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error