I rebased a fairly old topic branch onto master. Since there were quite a few conflicts during the rebase, I'd like to compare the old topic branch with the rebased one, to make sure I didn't accidentally remove or screw up any of the changes on topic. The closest I've gotten to this is diffing the results of git diff master...topic
and git diff master...topic-rebased
. This kind of works, but there's a lot of noise in the final diff from changes in the context code, line numbers, commit hashes, etc, in addition to it not being a very robust solution. Is there an easier way to do this?
You probably would want to diff the effective changes (patches) produced by each:
diff <(git log master..topic -p) <(git log master..old-place-of-topic -p)
This would effectively remove any changes introduced in master.
I was struggling with this same issue and came up with similar ideas as Ryan and Adam Dymitruk and found them not very satisfactory: Comparing the final diff is tricky and also doesn't show you where the "error" was introduced if you find it.
My current rebase workflow includes comparing each rebased commit with original one, so I can spot and correct potential errors as they appear and don't have to redo the rebase. I'm using the following pair of git alias to facilitate this:
rc = !git diff -w $(cat .git/rebase-merge/stopped-sha) > .git/rebase-merge/current-diff
rd = !git diff -w $(cat .git/rebase-merge/stopped-sha) | diff --suppress-common-lines .git/rebase-merge/current-diff - | cut -b 1-2 --complement | less
git rc
stores the diff between HEAD
the latest revision from the branch that is being rebased. After replaying the following commit, git rd
compares this stored diff to the diff between the new HEAD
and the next commit on the branch being rebased. Therefore this shows you only the difference ("error") introduces by replaying this last commit.
After inspecting the diff, call git rc
to update the stored diff and continue the rebase.
Instead of manually calling git rc
and git rd
you could even add them to your git-rebase-todo
so they're called automatically after each commit is replayed.
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