Last active
June 26, 2024 13:37
-
-
Save chrisandreae/4a2d3c2ecc8237c3fa884667e3080ebd to your computer and use it in GitHub Desktop.
Compare Rebase Script Fragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compareRebase () { | |
local newbranch oldbranch newcommit oldcommit ancestor | |
local opts=() | |
if [ "$1" = "-w" ] | |
then | |
opts+=("-w") | |
shift | |
fi | |
newbranch=${1:-$(git rev-parse --abbrev-ref HEAD)} | |
oldbranch=${2:-"${newbranch}@{u}"} | |
ancestor=${3:-origin/master} | |
oldancestor=${4:-"$ancestor"} | |
oldcommit=$(git commit-tree -p "$(git merge-base "${oldancestor}" "${oldbranch}")" "${oldbranch}^{tree}" -m "before rebase") | |
newcommit=$(git commit-tree -p "$(git merge-base "${ancestor}" "${newbranch}")" "${newbranch}^{tree}" -m "after rebase") | |
git range-diff "${opts[@]}" "${oldcommit}^..${oldcommit}" "${newcommit}^..${newcommit}" | |
} |
Utility for comparing the outcome of a rebase by comparing their diffs from a common ancestor (e.g. the master
branch). Assumes that the branch's upstream is the "before" state to compare with.
The advantage of using git range-diff
is that it gives you a proper colorized "diff-of-diffs", which can be very hard to read otherwise.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For comparison, I use this