gitgit-merge-conflict

How do I see the changes in a tree conflict ("deleted by us" or "deleted by them")?


When merging or rebasing two branches in git, and a file has been deleted in one but modified in the other, git gives a conflict. git status shows the file as "deleted by us" or "deleted by them".

I've found plenty of questions talking about how to resolve the conflict, including:

However, most of the answers assume you already know exactly what the conflict is, and just need to tell git to keep or delete the file.

How do you find out what changed in the version of the file that was not deleted? git simply leaves the whole file in the working copy, and doesn't mark any changes.

For instance:


Solution

  • If "deleted by us":

    git diff <your-branch>...<branch-you're-merging-to> /path/to/file
    

    If "deleted by them":

    git diff <branch-you're-merging-to>...<your-branch> /path/to/file
    

    From the git-diff man page:

    git diff [<options>] <commit>...<commit> [--] [<path>...]

    This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.

    This will only show you the changes made in the branch that didn't delete the file i.e. if the branch that deleted the file made any changes to it first those won't be reflected in the diff.

    If you're rebasing rather than merging then the "deleted by us" / "deleted by them" messages will be the other way round so use the other command.