0

I usually do rebases on my local branch to organize commits before pushing. Whenever I do a rebase and change something on a previous commit, I possibly get conflicts on the following commits. My problem is that Git is favoring local file changes instead of the remote file changes and that forces me to select all remote changes manually on each file every time I rebase. A screenshot of an example automatic merge shown in Meld:

enter image description here

merge configuration in .gitconfig:

[merge]
tool = meld
cmd = meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"
prompt = false
keepBackup = false

Is there a way to set git up to choose the remote file changes instead of the local file changes by default OR not to merge and allow me to resolve the conflicts manually?

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
Alan Evangelista
  • 2,888
  • 6
  • 35
  • 45

2 Answers2

0

meld has a --auto-merge option, that tries to merge together all changes that do not conflict.

Try setting your cmd line to :

cmd = meld --auto-merge "$LOCAL" "$BASE" "$REMOTE" --output "$MERGED"
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • git is already incorrectly auto-merging by picking local changes instead of remote changes. Adding any auto-merge to that will probably make no difference or make it worst, right? – Alan Evangelista Dec 06 '20 at 21:06
  • I overlooked that point : `$MERGED` is not "the result of the merge action", it just is "the path where the resulting merge should be saved". – LeGEC Dec 06 '20 at 21:15
  • I don't think that the file on disk has the same content as the base version, it is even possible that the merge action you are running do not reflect the actual merge git was trying to resolve. Use `$BASE` in the 3 way merge. – LeGEC Dec 06 '20 at 21:18
  • According to https://stackoverflow.com/questions/34119866/setting-up-and-using-meld-as-your-git-difftool-and-mergetool , $MERGED is "the partially merged file with the merge conflict information in it". That answer said that both the meld command with $MERGE I'm using right now OR the one with $BASE should work. My understanding is that in the first cmd, I should see the result of the merge done by git in the middle Meld pane. In the second cmd, I should see the common ancestor. My preferred solution is to see the first, but I want to git to correctly favor remote instead of local changes. – Alan Evangelista Dec 07 '20 at 13:44
0

The cmd configuration should be in a [mergetool "meld"] config block, not in the [merge] config block. As you currently have cmd in the wrong config block, it is ignored by Git and the default command is used, which uses $BASE (common ancestor of conflicting files) instead of $MERGED (partially merged file).

Correct setup:

[merge]
tool = meld
prompt = false
keepBackup = false

[mergetool "meld"]
cmd = meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"
Alan Evangelista
  • 2,888
  • 6
  • 35
  • 45