13

difftool has a great user friendly option for viewing diffs. It is the --dir-diff option - allowing you to arbitrarily browse through two directories.

The git mergetool has a very clumsy and unfriendly user interface. Solving merge conflicts has to be done in a strict order given by git.

Is there a possibility to setup a similar option like

$ git difftool --dir-diff 

say

$ git mergetool --dir-merge 

calling the directory compare of e.g. winmerge? Or do one has an alternative solution to provide a user friendly interface for solving multiple file merge conflicts?

2
  • Good question! I think it should be possible. I also hate you can't see there are 30 merge conflicts :-/ I think deterb has giving a workaround to see the files. But you don't see all changes in meld at once. Commented Sep 25, 2018 at 12:50
  • I agree, I used sublime merge on a trial and although I didnt have git auto-open that, it would recognise the merge in progress and show all files at once, that was much nicer Commented Oct 15, 2018 at 10:35

3 Answers 3

1

You can pass in a list of files to git mergetool'

To get a list of unmerged files, you can use git ls-files --unmerged $DIR'

In summary, do

git mergetool `git ls-files --unmerged $DIR` 
Sign up to request clarification or add additional context in comments.

1 Comment

If I do git mergetool -t meld ``git ls-files --unmerged $DIR```, I will still get meld` opened for each file individually, then I have to close meld, then meld gets opened again for next file etc - it does not show a side-by-side comparison of a directory as is the case with git difftool -t meld --dir-diff, which is what the OP was asking
0

There is a simple Python program called meld, but anything that visualises merges with three panes will do.

To use it for merge resolution, have it installed and, while in an unresolved-merge in git, type: $ git mergetool.

More on a topic you can read at: Painless Merge Conflict Resolution in Git

...I have found that the tools and interfaces available for performing merges do not equip programmers sufficiently to do them effectively. Often, a programmer will simply run git merge and hope that git will take care of the large majority of the hunks. Of the hunks that conflict, the usual merge strategy of the human at the helm is to use the surrounding context to roughly guess what the intended program is supposed to look like.

This article will hopefully demonstrate that there can be a much more measured process to the resolution of merge conflicts which takes the guesswork out of this risky operation...

3 Comments

As far as I know meld is just a merge tool like p4merge. I'm not bothering about solving conflichts in one file. When I merge I get e.g. 10 conflicting files
As far as I know, meld is just a merge tool like p4merge. I'm not bothering about solving conflichts in one file. When I merge I get e.g. 10 conflicting files. If I start with git mergetool, git will sequentially call each file conflict firing e.g. p4merge. I cannot select which conflict to solve first, second - I'm totally bound to the sequence dictated by git.
the way I understand this question - and what I need too - is that when you use git difftool -t meld --dir-diff, first you get a directory listing in the left and right panes of meld, telling you via color which files have changed and which not; then you can double-click a file, and you get a new tab in meld, which compares the file in left and right panes. I, like the OP, would like to do the same in mergetool - and this answer does not explain that, unfortunately.
0

Until the day --dir-diff or --dir-merge is supported by Git's mergetool, try one of these approaches.

For not-so-many conflicts:

  • Install and open VSCode (if not already).
  • Then go to "Source Control" section from side-bar.
  • From shown file-list's "MERGE CHANGES" section, right-click any conflicting file, and select "Launch merge tool".

Pros:

  • You're not forced to follow git's merge order.
  • All files are sorted by their folder path.
  • Any file's folder can be seen beside it.

Cons:

  • Folders can not be collapsed/folded.

For huge numbers of merge conflicts

Easier done than typed:

  1. First of all, undo your git merge and/or git pull, like:

    git reset --hard my-old-commit-hash 
  2. Then fake to have merged, like:

    git merge -s ours -m "ours-only-merge" origin/develop 

    Note to replace origin/develop with what you want to pull.

  3. Copy your project's hidden .git directory into a new-folder, which should be outside of your project-folder.

  4. Open console and cd into said new-folder, then ensure new-folder contains the commit you want to pull:

    git reset --hard my-to-be-pulled-commit-hash 
  5. Install a tool that supports folder compare (like "Beyond Compare 4" for Windows).

  6. Use said tool to compare new-folder with project-folder, and pull anything you need from new-folder into project-folder, like for Beyond Compare:

    • In Explorer, right-click on new-folder, and click "Select Left Folder For Compare" option.
    • Then in Explorer, right-click on project-folder and click "Compare to new-folder" option.
    • Beyond Compare opens, there-in first from "View" menu click "Show All", then select all files and folders with Ctrl+A.
    • Then right-click and click "Compare Contents" (while all files are yet selected).
    • Wait for progress to finish, then from "View" menu click "Show Differences".
    • Finally, open each file shown one-by-one, and do said "pull anything you need" from left to right.
  7. At last, remove new-folder, and in console cd into project-folder, then do --amend your changes, to ensure merge is no longer fake, like:

    git add . git commit --amend -m "My real merge" 

All done!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.