47

While merging some of the files failed to merge.

git status

shows both the successful and failed merges.

How to view only the unsuccessful merge files(conflict).

Currently i am using the following command to do this

 find . -name '*.cpp' -o -name '*.h' | xargs grep -l '<<<<'

3 Answers 3

63
git diff

This will only show failed merges after an unsuccessful merge. It has many options to configure what information you want to see. I suspect this is the exact option you are after:

 git diff --name-status --diff-filter=U

Also see http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#resolving-a-merge and http://www.kernel.org/pub/software/scm/git/docs/git-diff.html

1
  • 15
    If you want a clean list of files without the preceding U, then you can call git diff --name-only --diff-filter=U. This way you can pipe the output, for example do git diff --name-only --diff-filter=U | xargs subl.
    – JHannes
    Oct 21, 2015 at 12:21
13
git --no-pager diff --name-only --diff-filter=U

But since the goal is most likely to edit those files, the following will do perfectly:

vim $(git diff --name-only --diff-filter=U)

Or in Windows with VS Code:

foreach($file in $(git --no-pager diff --name-only --diff-filter=U)){code.cmd $file --wait}

Thanks to @JHannes comment from another answer for inspiration

12

Try this:

$ git ls-files -u
see man-git-ls-files
1
  • I like this command, because it will not display the status code before each file name. Since we already specify with the use of the filter we only want the unmerged files, this status code is of no use anymore and can be omitted. However, the same can be achieved via git diff --name-only --diff-filter=U. Nov 20, 2022 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .