Frequently, my colleagues will make some changes to an open pull request, rebase their local branch against the base branch - often squashing their changes into previous commits
Checkout this answer to another question which want to do something very similar to what you are trying to achieve.
It describe your situation like this:
newcommit -> the new pull request commit
oldcommit -> the old pull request commit
upstream -> the base branch commit the new pull request is based on
Now do this:
git commit-tree newcommit^{tree} -p oldcommit -p upstream -m "message"
git show
The idea is that commit-tree will fake a merge between oldcommit
and upstream
producing newcommit
tree and thus containing exactly the code of newcommit
.
It does not modify your current branch at all, it create a new headless commit and give you its ID.
This means git show
will list every modification as a conflict resolution, which is the exact difference between the new PR and the old one.
To be able to do that you need to have the previous PR in your git repository somewhere (if a force push has been performed the git history has been rewritten and can't be recovered unless you have it on your pc or you have access to the server reflog). Check VonC answer for details about this.
Assuming:
master
$BRANCH_NAME
origin/$BRANCH_NAME
You can do like this:
# fetch locally upstream changes (origin/$BRANCH_NAME)
git fetch
# produce the fake merge commit
git commit-tree origin/$BRANCH_NAME^{tree} \
-p $BRANCH_NAME \
-p `git merge-base master origin/$BRANCH_NAME` \
-m "message"
# see "fake" conflict resolution = difference between the two PR
git show
the git merge-base
is used to find the common ancestor between two branches, in this case to find the commit on which the new PR is based on in the base branch, if you prefer you can write the commit ID directly.