Search code examples
gitgithubgithub-api

git log results are different than git.api results


When I run the command "git log -m --name-only" on git. I came up with 2 results having the same commit-sha.enter image description here

When I use Github API for the same commit the result is like this;enter image description here

Why do I get the second result having the same commit sha(from e327....) on git? What does the second result means?


Solution

  • The more important question here is why you would expect these to be the same.

    Remember that git log is a method of querying reality—asking what's in the Git databases—by formulating some specific set of questions and getting answers. Meanwhile, GitHub's APIs are also methods of querying reality by asking specific questions to get specific answers, but the GitHub API questions are different. They're at most related to some of the questions you can ask with git log. Since you're asking different questions, you'll get different answers, and you should expect that. If you were going out on a date with your SO or spouse, you presumably would not expect to get the same answer to "what time will we have our date" and "what color clothing will you wear on our date".

    In any case, git log -m specifically directs the git log command to split a merge commit into two or more virtual commits. An actual merge commit has, by definition, 2 or more parents. If the merge commit has two parents, git log -m makes git log display that merge commit twice, with each display handled as if it were a single-parent commit with only one of those two parents.

    The reason to do this is because git log can show a diff of a commit against its (single) parent. The git log command does not show any diff of a merge commit against its multiple parents,1 but adding -m to git log makes it pretend that merge commit M, with the two parents P1 and P2, was really commit M-from-P1, with parent P1, and M-from-P2, with parent P2. That enables its diff-showing code.

    The GitHub API you invoked does not show a diff in the same way as the git log command, and hence does not have any reason to have an equivalent to the -m option. Instead, it appears to use the combined-diff code (see footnote 1) or some variant thereof.


    1The git log command can also be told to produce a combined diff. A combined diff is very different from two individual diffs. The options for this are -c and --cc; the two produce somewhat different output. See the Git documentation for details.