How to view only the unmerged files in git after a merge failure

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 '<<<<'

Solution 1:

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

Solution 2:

Try this:

$ git ls-files -u
see man-git-ls-files

Solution 3:

git --no-pager diff --name-only --diff-filter=U

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

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

Thanks to @JHannes from another answer's comment