4

After forking a Github repository I performed some changes in it. This was quite some time back, now the upstream branch is well ahead. Thus I wanted to merge those remote changes into my forked repo.

I hit upon a merge conflict in one file only. I went ahead and ran vimdiff as the mergetool to sort these things out. I only want to merge in the remote changes and discard the local ones.

But there are too many conflicting hunks in that file. Selecting changes to merge one by one is tedious to say the least.

  • Is there a shortcut to :diffget RE on all the conflicts in that file?
  • Maybe there is a method to select only a branches diff while discarding the other one in git?
devsaw
  • 1,007
  • 2
  • 14
  • 28

2 Answers2

11

Using Vims global select you can replace all diffs with either LOCAL, BASE or REMOTE

  1. Go to first line in file
:1
  1. Go into visual mode
 <Shift>-V
  1. Go to bottom of file, and select all lines
G
  1. Issue the diffget command on all lines
:diffget REMOTE
btburns
  • 111
  • 1
  • 3
  • for those who want to cut out 6 keystrokes, `:diffg RE` is sufficent for the last command. For those who want only local changes, use `:diffget LOCAL` or `difg LO` – Kit Nov 03 '20 at 00:24
2

Merging in git has two options that can default to using remote changes (theirs) or local changes (ours).

If you want to resolve conflicts only to the remote changes in a merge you would do the following:

git merge -Xtheirs <branch>

If you want to resolve conflicts only to the local changes in a merge you would do the following:

git merge -Xours <branch>

You can find more about advance merging strategies from the git advanced merging documentation.

Dom
  • 1,687
  • 6
  • 27
  • 37