user47827: This is more of a Git question but it is particularly relevant to Bitcoin Core PR review (or other open source projects with stringent review requirements).
You've done a review of a PR, the PR author force pushes and you want to compare the PR branch before the force push and after the force push. I've read you should use git range-diff in this scenario. But I'm not sure how to get Git to store the branch before the force push (the previous commit isn't in the Git history anymore) and compare to the latest version of the branch.

user5406: Git is like a blockchain: it only keeps the "best-commit-chain". A git push -f "reorgs" the prior chain of commits to a new "best chain".
If you checked out the PR before the force-push, your local git repository retains a copy of the commits from before the force-push. You can then use git fetch and git range-diff <branch> <upstream/branch> to compare the state prior and posterior of the force-push. If you have already checked out the updated branch after the force-push, your local repository still retains a copy of the prior commits (even if it doesn't show up in git log) and you can compare by calling git range-diff <old-commit-hash> <branch>. If you don't remember the old stale commit-chain-tip, you can look it up via git reflog.
Similarly to a Bitcoin node either having seen an extinct chain-tip when it was relevant or there being no (easy) way to get it, you cannot easily get an overwritten commit unless you created a local copy of the upstream branch before the force-push since overwritten commits are discarded by GitHub. In that case, just start reviewing from scratch.

TIL that GitHub meanwhile apparently does keep old commits around for a while. So, if you're lucky and it hasn't been cleaned up yet, you may be able to retrieve the "stale commit-chain-tip" via: git fetch upstream <commit-hash>

47827: <p>This is more of a Git question but it is particularly relevant to Bitcoin Core PR review (or other open source projects with stringent review requirements).</p>
<p>You've done a review of a PR, the PR author force pushes and you want to compare the PR branch before the force push and after the force push. I've read you should use <code>git range-diff</code> in this scenario. But I'm not sure how to get Git to store the branch before the force push (the previous commit isn't in the Git history anymore) and compare to the latest version of the branch.</p>
 5406: <p>Git is like a blockchain: it only keeps the &quot;best-commit-chain&quot;. A <code>git push -f</code> &quot;reorgs&quot; the prior chain of commits to a new &quot;best chain&quot;.</p>
<p>If you checked out the PR before the force-push, your local git repository retains a copy of the commits from before the force-push. You can then use <code>git fetch</code> and <code>git range-diff &lt;branch&gt; &lt;upstream/branch&gt;</code> to compare the state prior and posterior of the force-push. If you have already checked out the updated branch after the force-push, your local repository still retains a copy of the prior commits (even if it doesn't show up in <code>git log</code>) and you can compare by calling <code>git range-diff &lt;old-commit-hash&gt; &lt;branch&gt;</code>. If you don't remember the old stale commit-chain-tip, you can look it up via <code>git reflog</code>.</p>
<p>Similarly to a Bitcoin node either having seen an extinct chain-tip when it was relevant or there being no (easy) way to get it, you cannot easily get an overwritten commit unless you created a local copy of the upstream branch before the force-push since overwritten commits are discarded by GitHub. In that case, just start reviewing from scratch.</p>
<hr />
<p>TIL that GitHub meanwhile apparently does keep old commits around for a while. So, if you're lucky and it hasn't been cleaned up yet, you may be able to retrieve the &quot;stale commit-chain-tip&quot; via: <code>git fetch upstream &lt;commit-hash&gt;</code></p>
