Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git found out number of conflicts / list of conflicts in working folder

Tags:

git

dvcs

Is there any way to review list of conflicts (names of conflicting files and number of conflicts in it)?

The only thing I have discovered is to review pre-created .git/MERGE_MSG file... but this is not what I really searching for...

like image 406
shytikov Avatar asked Jun 13 '12 11:06

shytikov


2 Answers

Edit: Of course, the easy, obvious and over-engineering free answer is git status, as kostix notes. The disadvantage of this is that git status checks the status of the index compared to the working copy, which is slow, whereas the below only checks the index, a much faster operation.

To get the names of the files that are conflicted, use git ls-files --unmerged.

$ git ls-files --unmerged
100755 f50c20668c7221fa6f8beea26b7a8eb9c0ae36e4 1       path/to/conflicted_file
100755 d0f6000e67d81ad1909500a4abca6138d18139fa 2       path/to/conflicted_file
100755 4cb5ada73fbe1c314f68c905a62180c8e93af3ba 3       path/to/conflicted_file

For ease, I have the following in my ~/.gitconfig file (I can't claim credit, but I can't remember the original source):

[alias]
    conflicts = !git ls-files --unmerged | cut -f2 | sort -u

This gives me:

$ git conflicts
path/to/conflicted_file

To work out the number of conflicts in a single file, I'd just use grep for the ======= part of the conflict marker:

$ grep -c '^=======$' path/to/conflicted_file
2

You could add the following to your ~/.gitconfig as well as the conflicts line above:

[alias]
    count-conflicts = !grep -c '^=======$'
    count-all-conflicts = !grep -c '^=======$' $(git conflicts)

This will give you:

$ git conflicts
path/to/a/conflicted_file
path/to/another/different_conflicted_file

$ git count-conflicts path/to/a/conflicted_file
2

$ git count-all-conflicts
5
like image 163
me_and Avatar answered Oct 18 '22 22:10

me_and


git status shows files which are failed to be merged automatically and have conflicts, with the hint of how to record the resolved state of such files.

like image 20
kostix Avatar answered Oct 18 '22 20:10

kostix