tomjen
tomjen

Reputation: 3889

What is the git command used by gitlab on merge requests to show changes?

Gitlabs merge requests have a 'changes' button which shows exactly the changes that will happen to the target branch if the merge is accepted.

I would like to be able to see that information on the commandline, without having to create a merge request.

Upvotes: 1

Views: 1369

Answers (2)

VonC
VonC

Reputation: 1324557

This is clearer with GitLab 13.9 (February 2021)

Merge Refs for changes in merge requests

Merge request diffs have been calculated by git diff target...source which compares HEAD of the target with the merge base of target and source. This works well, until changes from the target branch are merged into the source branch, creating a complete mess of the diff.

Merge requests now compare to <default branch> (HEAD) by default when viewing the changes tab of a merge request.
This provides a more accurate and up-to-date diff of the changes during your review.

See Documentation and Epic.

In particular:

Before, as noted in issue 15140, it was git diff from...to:

The reason why we use git diff from...to instead of git diff from to, is that the latter with include all differences between the heads of the two branches, which means that any changes that were made to the target branch (from) after the source branch (to) was created, will show up as deletions in the diff.

In the majority of cases, git diff from...to is exactly what we want, but since it compares using the merge base, not the actual commit content, it does not handle cherry-picks correctly.

After: see "Merge request diffs against the HEAD of the target branch"

Consider the following case, in which the source branch is feature_a and the target is master:

  • Checkout a new branch feature_a from master and remove file_a and file_b in it.
  • Add a commit that removes file_a to master.

The merge request diff still contains the file_a removal while the actual diff compared to master’s HEAD has only the file_b removal.
The diff with such redundant changes is harder to review.

In order to display an up-to-date diff, in GitLab 12.9 we introduced merge request diffs compared against HEAD of the target branch: the target branch is artificially merged into the source branch, then the resulting merge ref is compared to the source branch in order to calculate an accurate diff.

Upvotes: 0

C4stor
C4stor

Reputation: 8026

It would simply be git diff target..proposedMerge I think

For your command line purposes target and proposedMerge can be:

  • sha1 of commits
  • branch names (locally, like "master", or remote, like "origin/develop" <--- don't forget to git fetch first !)
  • relative position on branch names, like master~2, or HEAD^

For output visualisation, there are various plugins available for git diff, you can pick one you like if you don't like the default one !

Upvotes: 1

Related Questions