Git - automatically create distinct files for versions on conflict

Viewed 1306

When Git detects a conflict during merge, the default behaviour is to fill the file with <<< >>> === markers.

This is OK most of the time, but sometimes I'd like to resolve conflicts differently and I'd just like Git to create distinct files:

  • original version,
  • changed version A,
  • changed version B.

How to achieve that?


If there's no simple command to create those files in one go (which is somewhat surprising), maybe there is a way to extend Git so that it would do it? A custom mergetool or something? Just an idea.


Solution:

I've settled for a variant of @Karl Bielefeldt's answer:

savefiles.sh

#!bash
BASE=$1
LOCAL=$2
REMOTE=$3
MERGED=$4

cp "$BASE" "$MERGED.git_BASE"
cp "$LOCAL" "$MERGED.git_LOCAL"
cp "$REMOTE" "$MERGED.git_REMOTE"

# never mark the conflict as merged
exit 1 

config

mergetool.savefiles.cmd=/path/to/savefiles.sh $BASE $LOCAL $REMOTE $MERGED
mergetool.savefiles.trustexitcode=true
3 Answers
Related