Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have meld as git mergetool to only show conflict and not differences?

When I use meld as git mergetool for solving conflict while merging, meld shows me the differences between local/output and remote/output files (in blue or green) that git automatically solves, and not only the actual conflicts (that are red highlighted). And when I click on the down arrow, it goes to the next (blue/green) difference, and not to the next conflict (red). In this topic, a picture illustrates this.

How could I

  • ignore the difference that are not conflict
  • or go to the next conflict (like in kdiff3), without stopping on the differences ??
like image 989
janou195 Avatar asked Mar 06 '14 13:03

janou195


3 Answers

Add the following to your .gitconfig:

[mergetool "meld"]
  cmd = meld --auto-merge "$LOCAL" "$BASE" "$REMOTE" --output "$MERGED"

This is the same command Git runs by default with --auto-merge specified so that Meld automatically resolves what it can.

like image 127
Joseph Thomson Avatar answered Nov 12 '22 00:11

Joseph Thomson


In addition to meld-specific parameters, you now have new Git options:

With Git 2.31 (Q1 2021), "git mergetool"(man) feeds three versions (base, local and remote) of a conflicted path unmodified.
The command learned to optionally prepare these files with unconflicted parts already resolved.

See commit 9d9cf23, commit de8dafb, commit 98ea309 (09 Feb 2021) by Seth House (whiteinge).
(Merged by Junio C Hamano -- gitster -- in commit 78a26cb, 17 Feb 2021)

mergetool: add hideResolved configuration

Original-implementation-by: Felipe Contreras
Signed-off-by: Seth House

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 conflicts.

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 so this behavior defaults to true.
However it can be globally disabled by setting mergetool.hideResolved to false.

See "Mergetools: Stop doing three-way merges!"

git config now includes in its man page:

mergetool.hideResolved

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.

In the OP's case:

git config --global mergetool.meld.hideResolved true

This is described in:

mergetool: add per-tool support and overrides for the hideResolved flag

Helped-by: Johannes Sixt
Helped-by: Junio C Hamano
Signed-off-by: Seth House

Add a per-tool override flag so that users may enable the flag for one tool and disable it for another by setting mergetool.<tool>.hideResolved to false.

In addition, the author or maintainer of a mergetool may optionally override the default hideResolved value for that mergetool.
If the mergetools/<tool> shell script contains a hide_resolved_enabled function it will be called when the mergetool is invoked and the return value will be used as the default for the hideResolved flag.

hide_resolved_enabled () {
    return 1
}

Disabling may be desirable if the mergetool wants or needs access to the original, unmodified 'LOCAL' and 'REMOTE' versions of the conflicted file.

For example:

  • A tool may use a custom conflict resolution algorithm and prefer to ignore the results of Git's conflict resolution.
  • A tool may want to visually compare/constrast the version of the file from before the merge (saved to 'LOCAL', 'REMOTE', and 'BASE') with Git's conflict resolution results (saved to 'MERGED').

git config now includes in its man page:

mergetool.<tool>.hideResolved

Allows the user to override the global mergetool.hideResolved value for a specific tool.

like image 36
VonC Avatar answered Nov 12 '22 01:11

VonC


In meld, you can click Changes > Merge All, which will merge most changes except for the conflicts.

like image 6
chrisdembia Avatar answered Nov 11 '22 23:11

chrisdembia