git – How to see conflicting files

Question:

Problem:

  • Doing git merge got a conflict for 168 files, I fixed more than half of them with a regular. But you need to find out what failed to fix. The usual git diff shows all changed files, and you don't see what else needs to be tweaked.

What do you need:

  • Find a cool command in git that will show me only those files that still need to be tweaked.

What have I tried:

  • git diff --name-status thought that unpatched files should have a special status, but both options show both U and M
  • git status -sb shows just files that are not yet in the index

Examples:

  • git diff not-resolved.file показывает примерно такое

    git diff
    diff --cc hello.rb
    index 0399cd5,59727f0..0000000
    --- a/hello.rb
    +++ b/hello.rb
    @@@ -1,7 -1,7 +1,11 @@@
      #! /usr/bin/env ruby
    
      def hello
    ++<<<<<<< HEAD
     +  puts 'hola world'
    ++=======
    +   puts 'hello mundo'
    ++>>>>>>> mundo
      end
    
      hello()
    
  • git diff resolved.file показывает особыми палочками как был решен конфликт

    $ git diff
    diff --cc hello.rb
    index 0399cd5,59727f0..0000000
    --- a/hello.rb
    +++ b/hello.rb
    @@@ -1,7 -1,7 +1,7 @@@
      #! /usr/bin/env ruby
    
      def hello
    -   puts 'hola world'
     -  puts 'hello mundo'
    ++  puts 'hola mundo'
      end
    
      hello()
    

Reflections:

  • the examples show that git can clearly see the difference between these files, that is, it seems to have marked them somehow.
  • perhaps the task is generally unsolvable, maybe git just looks at the output that there is no "++ <<<<<<< HEAD" and decorates the output differently, taking into account the state of theirs and ours versions
  • if git somehow marks the fixed files, then how would it mark the file in the first 2 conflicts, and one was fixed and the other was not
  • the examples show that

    • + means that the line came from the previous version and is still present in the file
    • - denotes what came from the previous version but is no longer present in the file
    • ++ denotes that the line only exists in the new file.
  • sadly so far the most reliable option is grep -H -r "<<<<<<< HEAD" .

  • git makes the markers of the beginning and end of the conflict "<<<<<<< HEAD" for a reason, maybe the absence of these markers tells him that the conflict may have been resolved, and you can find out without grep

Answer:

git diff --name-only --diff-filter=U | xargs grep '<<<<<<< HEAD' for bash, you can simply get all unmerged files and filter those that contain HEAD

Scroll to Top