I want to be able to see changes in a branch, since I last reviewed it, but ignoring the changes in master that happened in the meantime.
F - G H - I
/ /
A - B - C - D - E
I have two commit ranges c3af8fc5..7ccc4b49
(represented by B - G
) and 4dfdabdd..301a443c
(represented by E - I
).
Imagine, you're doing code review for your colleague, you checkout his branch on local and your HEAD
is now pointing to G
. You do the code review and move on to something else.
Some time passes, new commits appeared in master (C
, D
and E
) and your colleague have resolved the comments from your review. He squashed the changes to commits F
and G
, because he renamed method introduced in F
and fixed its usage in G
. He also rebased the branch on master, to make sure everything works.
Now you want to make code review again, but you're lazy to do a code review of the whole branch again, so you wanna only see what changed from the last time. You still have the old refs fetched locally. What do you do?
You could do something like git-diff G I
, but that would also show you what changed in master which doesn't help you at all.
You could also rebase the old refs on the current master and then diff them. That might help, but there also might be a lot of conflicts, which could make just reviewing the whole branch again easier.
I've tried diffing patches
diff <(git-diff c3af8fc5...7ccc4b49) <(git-diff 4dfdabdd...301a443c)
it helps me to direct my attention somewhere, but it is very crude.
Do you know any nicer, more native way to solve this problem? Thanks.
Edit: I've just discovered interdiff, which makes diffing two diffs much nicer
interdiff <(git-diff -U100 c3af8fc5...7ccc4b49) <(git-diff -U100 4dfdabdd...301a443c) | colordiff
but still, it lacks the context that git might provide - so... is there anything better?
So the solution is to use the new git range-diff.
Simply run git range-diff c3af8fc5..7ccc4b49 4dfdabdd..301a443c
, or even simpler git range-diff 7ccc4b49...301a443c
might work unless you've done some really crazy rebase.
For a better explanation, I'm referencing few related topics
The simplest way may be : visually compare the diffs
Fire up two diff viewers, and compare the two views when you want to see what comes from the rebased revision :
# view the "old" patch :
git difftool -d B G
# view the "new" patch :
git difftool -d H I
You can focus on modified files only :
git diff --name-only B G
will list the names of the modified files between B and G.
You can target only modified files using for example :
# compare G and I,
# looking only at files modified between B and G, or between E and I :
git difftool -d G I -- $(
git diff --name-only B G; git diff --name-only E I
)
You can also try rebasing B..G
on top of E
on your local machine, if it doesn't trigger too many conflicts, and then look at the diff :
git checkout G
# as an option, you can make a temporary branch :
git checkout -b wip/G
# rebase on the tip of 'master' :
git rebase E
# look at the diff between "rebased G" and I
git difftool -d wip/G I
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With