3

Working with github/gitlab, using feature branches in many cases pull requests go out of date while waiting for a review and need to be rebased on top of the new target branch (master) after a while.

This will sometimes create conflicts that need to be solved.

After a rebase I would like to compare the old and the new branch in relation to the target branch, to verify no errors have been made while solving the conflicts. Meaning I would like to verify which lines are going to change after merging the new version of the PR.

So basically I would like to diff the result of git diff branch origin/master and git diff origin/branch origin/master - what changed in the diff output on the PR view of github/gitlab between the old and new versions.

Is there a command to do this?

2
  • Wouldn't git diff branch origin/branch do the diff you want, given that you have rebased branch? Commented Dec 1, 2020 at 8:07
  • No, that will contain the diff that was merged into branch from master Commented Dec 3, 2020 at 11:25

1 Answer 1

2

Yes, you can use the form of git-diff that takes multiple commits:

git diff <commit> <commit>…​ <commit>

From the documentation:

This form is to view the results of a merge commit. The first listed must be the merge itself; the remaining two or more commits should be its parents.

In your case, you want to compare the merge commit between the rebased branch and origin/master with the merge commit between the old origin/branch and origin/master; the comparison then becomes:

git diff branch origin/master origin/branch 

where branch is the "merge commit" and origin/master and origin/branch are its "parents".

In case of a conflict, Git is going to produce the following diff:

- line in origin/master (the first "parent" commit) - line in origin/branch (the second "parent" commit) + line in branch (the merge commit) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.