Question

how do I open from terminal window only files with conflicts during git/mercurial merge in textmate/sublime text2 editors

Was it helpful?

Solution

You can use the following to open all files with git merge conflicts in sublime text:

git diff --name-only | uniq | xargs subl

OTHER TIPS

I wanted to add another answer. git diff --name-only will give you all files that have diffs. This is why sometimes it will yield duplicate entries because it marks the file as "modified" as well as in a merge conflict state. Piping it into uniq is a good solution for this but git diff --name-only will also include files you might have purposely changed so it doesn't actually filter only files with merge conflicts. When you are in the middle of rebasing, this is probably not going to happen often though I would say in most cases @StephanRodemeier's answer works.

However, what you can do though is leverage the --diff-filter option which assigns a states to files. See more in the docs

--diff-filter=[(A|C|D|M|R|T|U|X|B)…​[*]]

Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, …​) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.

It seems when files are in the both modified state, the diff status gets set to U (Unmerged) and M (Modified) so you can filter for only Unmerged files.

git diff --diff-filter=U --name-only | xargs subl

Should work without needing to pipe into uniq

Another thing you can consider is simply setting your editor as the difftool i.e. for VSCode documentation specifies how to do this by adding this to your .gitconfig

[diff]
    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top