Reputation: 3889
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
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 comparesHEAD
of the target with the merge base oftarget
andsource
. 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 ofgit 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 ismaster
:
- Checkout a new branch
feature_a
frommaster
and removefile_a
andfile_b
in it.- Add a commit that removes
file_a
tomaster
.The merge request diff still contains the
file_a
removal while the actual diff compared to master’s HEAD has only thefile_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
Reputation: 8026
It would simply be git diff target..proposedMerge
I think
For your command line purposes target and proposedMerge can be:
git fetch
first !)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