Video in progress

Strong Middle 🌿 Git

What is the difference between `git log main..feature` and `git log main...feature`? And what do two and three dots mean in `git diff`?

In log, A..B means commits that are in B and not in A, and A...B means commits that are on only one side. In diff, A..B simply compares A and B, while A...B shows the changes from the merge base to B, that is, only the changes on B's side.

📖 Answer

main:     A---B---E---F
               \
feature:        C---D

git log:

  • main..feature → C, D (what goes into the PR);
  • feature..main → E, F (what has landed on main since you branched);
  • main...feature → C, D, E, F. If you add --left-right, which side each belongs to is shown with < and >.

In git diff the meaning is different, and this is where people often slip:

  • git diff main..feature is the same as git diff main feature: the states of F and D are compared directly. The changes in E and F show up in the diff as "minus", as if you had deleted them;
  • git diff main...feature compares B (the merge base) and D. Only the changes made in the feature.

GitHub and GitLab show the PR diff with exactly three dots. That is why in a CI script, to get the "changed files", you need three dots too:

git diff --name-only origin/main...HEAD

If you write two dots, files that others brought into main also come out as "changed", and CI builds modules it does not need to.