2

We have a branch "prod" into which a PR is going to be merged. The Left Hand Side of the "Compare" dialog thus should be showing the "prod" branch content. It looks like this:

<span class="file-name" [innerText]="row.ts | date:'MMM dd, yyyy, hh:ss a'"></span>

However the "prod" branch content actually contains a formatting bug fix :

<span class="file-name" [innerText]="row.ts | date:'MMM dd, yyyy, hh:mm:ss a'"></span>

This behavior is repeatable across multiple team members so it does not appear to be a browser caching issue. Also this can be seen when running git diff from the command line using the three-dot syntax.

git diff prod...prod-feature | grep hh

Why does this happen?

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

1 Answers1

2

This is a great question. There are two main formats of diffs and they show slightly different things.

The .. (two dot) version shows the difference between the version on the left and the version on the right. In other words, git diff A..B (or just git diff A B) looks at the differences between A and B.

The ... (three dot) version shows the differences in B, starting from the merge base of A and B. In other words, as the manual page states, git diff A...B is equivalent to git diff $(git merge-base A B) B.

In your case, prod-feature is based off an older revision of prod. The latter has progressed, and you're seeing the diff between the version of prod that prod-feature was based off, and prod-feature itself.

Now, you might ask yourself, why do we even have this three-dot functionality? Because it shows differences only in one branch. Since your prod branch has progressed, git diff prod..prod-feature would end up showing a diff that deletes the new data you've added in prod, when in fact the result of a merge will not do that. In addition, it will add a tremendous amount of noise in many cases. A three-dot diff makes it easier to reason about what changes will be added to and removed from the main branch when the feature branch is merged.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Tried this out: the double-dot version is what we want Can _github_ be persuaded to display the double-dot version instead of the triple? – WestCoastProjects Aug 31 '21 at 01:08
  • 1
    @WestCoastProjects Consider reading the docs. https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons – matt Aug 31 '21 at 01:55