Is there a way to compare 2 unrebased git branches?

Viewed 70

There is a branch b1. I created a new branch b2 from b1 (for backup). Now I have re-based b1 over master. I also added some code while re-basing. Now I want to find the difference between b1 and b2 for only the files I changed, not the changes from the master branch. GitHub's compare feature is not working for me. Is there an option other than manually going through the changes?

1 Answers

If your tree looks like this:

* H (feature-rebased) second commit of feature
* G first commit of feature
* F (main) third change to main
* E second change to main
* D first change to main
| * C (feature) second commit of feature
| * B first commit of feature
|/
* A (origin/main)

You can view the differences in your patches feature and feature-rebased via

git range-diff origin/main..feature main..feature-rebased

According to the git range-diff documentation, you can also use

git range-diff @{u} @{1} @

immediately after rebasing and resolving merge conflicts to compare the changes introduced by the rebase.

Related