Search code examples
gitmergeconflict

Git Merge not marking up all differences in conflicting text files


I'm testing out GIT branch merging and conflict resolution with changes to a simple text file.

I've checked-out a branch called issue1, made an update to File_A and committed the changes.

I've then checked-out master, made multiple updates to File_A and committed the changes

When I then attempt to git merge issue1 i get the expected

Auto-merging /File_A
CONFLICT (content): Merge conflict in /File_A
Automatic merge failed; fix conflicts and then commit the result.

however when I open the file the conflict markup only highlights the first difference it finds not any of the others.

<<<<<<< HEAD
<?xml version="1.0" encoding="utf-7" ?>
=======
<?xml version="1.0" encoding="utf-8"?>
>>>>>>> issue1

Is it possible to easily highlight all the differences in this way or am I going to have to use a different means for conflict resolution?


Solution

  • Here are some common commands I use.

    to get a quick overview

    git diff -- shortstat master issue1 
    

    to overview of differences per file

    git diff --stat master issue1
    

    To highlight the differences (not the conflicts) between two commits for a file. THis will force the ouput to go to the terminal. See 'git help config' diff.external section to use an external diff editor.

    git diff --no-ext-diff master issue1 -- File_A
    

    If the files to be merged contain changes but in different parts of the file, they will not show up as conflicts. The merged (result) file will bring both changes. It only conflicts if both files want to change the same lines.