Skip to content

Question: Explain compare and merge request diffs rational

As a somewhat long time git user now, I'm used to the git diff command that gives me the differences between a ref and another, regardless of history.

Gitlab compare and merge request changes use another way. They display changes between the source branch and the last common commit. This has several impacts:

  1. A gitlab "compare ref1 vs ref2" is not the opposite of a "compare ref2 vs ref1".
  2. The merge changes does not show the difference between the target branch as it is now and the source branch, as I expected.

Example in the dr4Ke/gitlab-issue-example> project.

This is the history graph:

Capture_d_écran_de_2020-09-11_12-33-18

Comparing branch1 and master with git diff gives me:

$ git diff master..branch1
diff --git a/README.md b/README.md
index f3287c7..d42096b 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,3 @@
-This is a README for a different issue.
+This is a new issue.
+
+Some more doc.

$ git diff branch1..master
diff --git a/README.md b/README.md
index d42096b..f3287c7 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1 @@
-This is a new issue.
-
-Some more doc.
+This is a README for a different issue.

We can see the second is the opposite of the first.

Now gitlab branch comparison gives me this:

Capture_d_écran_de_2020-09-11_12-36-24

Capture_d_écran_de_2020-09-11_12-36-40

We see that one is not the opposite of the other. And it's also not what would happen if I merge branch1 into master.

I consider the compare function of gitlab more as a "history diff" than a "code diff".

I don't understand why we would want to see changes between an old target branch and the source branch rather than the current target and the source. I didn't find something explaining this behavior in past issues (but there are many and I may have missed it) or in the documentation.

Edited by Christophe Drevet