Search code examples
gitgithubmergeversion-controldvcs

What is the diff of a merge commit actually showing on GitHub?


Consider the following commit page:

https://github.com/SignalR/SignalR/commit/cc5b002a5140e2d60184de42554a8737981c846c

Typically with Git, a commit is a set of changes applied on top of a previous codebase, so, considering the following tree:

enter image description here

Looking at the diff of 1ca1b6b would show the codebase as of ca2cac9 on the left, and the changes applied in that commit on the right. With a merge commit, what are we seeing on the left hand side? i.e. considering the following tree:

enter image description here

If we view commit 1e25f98 on GitHub, what's on the left? 06f5be1? And what about with a more complicated tree? Or a merge between three branches? Does it just show a diff between the last common point in history?


Solution

  • petrpulc's answer is correct in substance and I've upvoted it, but to address GitHub specifically, what GitHub does to show this diff is to ignore the second parent entirely.

    You can see the same diff on the command line using:

    git log -p --no-walk --first-parent -m cc5b002a5140e2d60184de42554a8737981c846c
    

    or, simpler:

    git show --first-parent cc5b002a5140e2d60184de42554a8737981c846c
    

    (We need the --no-walk in git log to prevent Git from looking at more commits, while git show implies it. We need the --first-parent to make Git look only at the first parent, and for git log, we need -m or -c or --cc to force git log to show a patch, as -p normally skips showing patches for merges, even if we use --first-parent to trim away the remaining parents.)