mergetool: add hideResolved configuration

The purpose of a mergetool is to help the user resolve any conflicts
that Git cannot automatically resolve. If there is a conflict that must
be resolved manually Git will write a file named MERGED which contains
everything Git was able to resolve by itself and also everything that it
was not able to resolve wrapped in conflict markers.

One way to think of MERGED is as a two- or three-way diff. If each
"side" of the conflict markers is separately extracted an external tool
can represent those conflicts as a side-by-side diff.

However many mergetools instead diff LOCAL and REMOTE both of which
contain versions of the file from before the merge. Since the conflicts
Git resolved automatically are not present it forces the user to
manually re-resolve those conflicts. Some mergetools also show MERGED
but often only for reference and not as the focal point to resolve the

This adds a `mergetool.hideResolved` flag that will overwrite LOCAL and
REMOTE with each corresponding "side" of a conflicted file and thus hide
all conflicts that Git was able to resolve itself. Overwriting these
files will immediately benefit any mergetool that uses them without
requiring any changes to the tool.

No adverse effects were noted in a small survey of popular mergetools[1]
so this behavior defaults to `true`. However it can be globally disabled
by setting `mergetool.hideResolved` to `false`.


Original-implementation-by: Felipe Contreras <>
Signed-off-by: Seth House <>
Signed-off-by: Junio C Hamano <>
Seth House 2 years ago committed by Junio C Hamano
parent 6d3ef5b467
commit 98ea309b3f
  1. 10
  2. 14
  3. 18

@ -40,6 +40,16 @@ mergetool.meld.useAutoMerge::
value of `false` avoids using `--auto-merge` altogether, and is the
default value.
During a merge Git will automatically resolve as many conflicts as
possible and write the 'MERGED' file containing conflict markers around
any conflicts that it cannot resolve; 'LOCAL' and 'REMOTE' normally
represent the versions of the file from before Git's conflict
resolution. This flag causes 'LOCAL' and 'REMOTE' to be overwriten so
that only the unresolved conflicts are presented to the merge tool. Can
be configured per-tool via the `mergetool.<tool>.hideResolved`
configuration variable. Defaults to `true`.
After performing a merge, the original file with conflict markers
can be saved as a file with a `.orig` extension. If this variable

@ -239,6 +239,13 @@ checkout_staged_file () {
hide_resolved () {
git merge-file --ours -q -p "$LOCAL" "$BASE" "$REMOTE" >"$LCONFL"
git merge-file --theirs -q -p "$LOCAL" "$BASE" "$REMOTE" >"$RCONFL"
mv -- "$LCONFL" "$LOCAL"
mv -- "$RCONFL" "$REMOTE"
merge_file () {
@ -276,7 +283,9 @@ merge_file () {
base_mode= local_mode= remote_mode=
@ -322,6 +331,11 @@ merge_file () {
checkout_staged_file 2 "$MERGED" "$LOCAL"
checkout_staged_file 3 "$MERGED" "$REMOTE"
if test "$(git config --type=bool mergetool.hideResolved)" != "false"
if test -z "$local_mode" || test -z "$remote_mode"
echo "Deleted merge conflict for '$MERGED':"

@ -828,4 +828,22 @@ test_expect_success 'mergetool -Oorder-file is honored' '
test_cmp expect actual
test_expect_success 'mergetool hideResolved' '
test_config mergetool.hideResolved true &&
test_when_finished "git reset --hard" &&
git checkout -b test${test_count}_b master &&
test_write_lines >file1 base "" a &&
git commit -a -m "base" &&
test_write_lines >file1 base "" c &&
git commit -a -m "remote update" &&
git checkout -b test${test_count}_a HEAD~ &&
test_write_lines >file1 local "" b &&
git commit -a -m "local update" &&
test_must_fail git merge test${test_count}_b &&
yes "" | git mergetool file1 &&
test_write_lines >expect local "" c &&
test_cmp expect file1 &&
git commit -m "test resolved with mergetool"