You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
amending PR branches via force-push causes unreachable commits to be garbage-collected #997
This issue is for tracking just one of those problems: when you rewrite PR history, there is no guarantee that commits from older versions of the PR will be preserved, unless they are still reachable from the PR branch head. (See #998 and #999 for other, separate problems with force-pushing to PR branches.)
Since we can't easily trigger GitHub's garbage collection, it's hard to definitively prove this is a genuine issue. However there is some strong evidence:
It is already documented in reviewable.io's FAQ that they have to pull tricks to "pin" commits to ensure that they don't disappear when a PR is updated via force-push, so this provides strong evidence that I'm right.
I was also attempting to prove it via an experiment in aspiers/test#3 - I previously thought that if within a few months of writing this, the test commit was still viewable, then maybe this was not genuine issue. But at the time of writing (editing) this text, the commit was still visible, so bearing in mind the above evidence, it's more likely that there is something else going on here. For example, maybe my attempt to construct an obfuscated URL which didn't accidentally prevent the commit from being garbage-collected didn't work. Or maybe the garbage-collection is triggered not by the age of orphans, but by the number of orphans, or when the number of objects exceeds a threshold, in which case my test repository will be useless in this experiment since it has almost zero traffic. GitHub might even be using git-gc(1) behind the scenes.
Reacted by Ayush Tiwari, Andrew, Cypress Frankenfeld, Joseph Frazier, Dmitry Pashkevich, Alan Pierce, Maxime Gabut, Shane da Silva, Ajiemar Santiago, Jan Melcher and 20 more
I'm also attempting to prove it via an experiment in aspiers/test#3 - if within a few months of writing this, the test commit is still viewable, then maybe I was wrong after all, in which case this issue can be closed.
Actually, the garbage-collection could be triggered not by the age of orphans, but by the number of orphans, in which case my test repository will be useless in this experiment since it has almost zero traffic.
I've just remembered that GitHub's UI itself explicitly admits this issue. See how after I clicked on the icon showing my review of a previous version of a PR, it presented this screen which says "Sometimes commits can disappear after a force-push":
+1 for this one, our project uses a rebase-driven PR approach as well. Supporting push -f properly so that rebased PRs display their history would be a major help for us.
Reacted by Adam Spiers, Markus Zoeller, sledge909, Eleos91, Bojan Potočnik, Gustavo Romero and Hitesh Kumar Saini
Is it also easy to bulk delete tags? E.g. by wildcard?
I think a graphical UI might be useful, to let you filter the tags, then select a subset of them, then delete.
There could be different tag prefixes for "commit lost after rebase" vs "commit referred to in a github comment", so you can delete one category without deleting the other.
Auto-generated tag names could have a pattern like archive/COMMIT_DATE/COMMIT_ID, so they don't have to be random. More parts could be added for commit author, associated branch name (if there was a branch at the time), PR or issue number.
Btw one problem with auto-adding tags is that it pollutes your local repository when you git fetch --tag. In most cases, orphan commits are not desirable to keep.
This is a real problem for our team. We just migrated from Bitbucket, where they keep and display amendment history of commits. If you have commits A->B->C and e.g. amend B to B' (and thus C becomes C' with a different parent) via interactive rebase and force push the branch, the whole action will be recorded as -C -B +B' +C'. The whole action and all related commits (including B and C), as well as all review messages on those commits are retained and easily accessible from the web UI.
I personally think the Bitbucket way that is the correct way to implement regarding this issue, since a PR is supposed to be amendable and the amendment history, including any comments, are valuable for historical accounts.
Reacted by Joseph Frazier, Henning Claßen and Lucas Clemente Vella
The only way we can know for sure if this is resolved is if GitHub announces they've fixed it. If noone sees a single instance of the problem in the next few months then yeah maybe it's fixed, but even then there is no way to be sure.
Just faced this issue in a corporate instance of GitHub: It deleted the previous commit after a forced push, and it couldn't even find the original commit after I pushed it to a different branch.
GitLab does this well, offering a great UI for selecting which two inter-revision diffs in a PR you want to see the changes between. Not sure why GitHub doesn't see this as a valuable and important feature.
@erikeckhardt I believe you are discussing #999 rather than this issue.
It seems you are correct as far as the UI portion. My mistake!
For the functionality portion, this case #997 does seem like a prerequisite to such a UI working. Not garbage-collecting PR commits from history, despite them being technically "unreachable" from any branch, would at least allow the "force pushed" link in the Conversation log to work, which would provide a UI of some kind.
For reference:
usernameforce-pushed the branch_name_here branch from bfe2d5e to ad975e2 3 hours ago
Theoretically, this could be pretty easily achieved by maintaining a hidden branch per PR that has all PR versions in history. Don't ever display these hidden branches to the user or let them be pulled down to git clients, and garbage collection is automatically prevented from disposing of those commits.
@erikeckhardt I believe you are discussing #999 rather than this issue.
It seems you are correct as far as the UI portion. My mistake!
No worries ;-)
For the functionality portion, this case #997 does seem like a prerequisite to such a UI working. Not garbage-collecting PR commits from history, despite them being technically "unreachable" from any branch, would at least allow the "force pushed" link in the Conversation log to work, which would provide a UI of some kind.
Yes, you're correct. That's why I filed the three issues #997, #998, and #999 in that order ;-) The later ones depend on the earlier ones.
For reference:
usernameforce-pushed the branch_name_here branch from bfe2d5e to ad975e2 3 hours ago
Theoretically, this could be pretty easily achieved by maintaining a hidden branch per PR that has all PR versions in history. Don't ever display these hidden branches to the user or let them be pulled down to git clients, and garbage collection is automatically prevented from disposing of those commits.
In GitHub's backend, it probably wouldn't even need to be a branch; it could just be a ref, e.g. in the format refs/pr/X/Y where X is the PR number and Y is the number of times the PR branch head has been updated. And this way this family of refs would even be helpful if it wasn't hidden, because it wouldn't pollute the branch list, but it would still be available for download to the local repo to aid with local history navigation. It's worth noting that GitHub clients could already choose to create refs like this, and maybe some already do.
it could just be a ref, e.g. in the format refs/pr/X/Y where X is the PR number and Y is the number of times the PR branch head has been updated.
At first I was thinking, no need for the Y part, because we won’t need each history entry to be at a tip. We could just add a commit each time the PR branch was force-pushed to, so long as it brought the index to the correct state. But then I realized that without the same history, the SHA would be different, which wouldn’t prevent garbage collection.
But, having one ref per PR version would be additionally useful, because sometimes I want to view a diff of a history that never existed, which these entries would help build—if a PR submitter rebases an unmerged PR branch onto the target branch, and there were unpushed local changes included, then the diff between versions includes the rebased changes and obscures the submitter’s changes. While this is best solved by git clients or scripting, it can be worked around by pulling up the ref of the prior version, rebasing that onto the same ref the PR was rebased onto, and finally adding the result as another commit in the previous version’s ref (with the extra step of having to look up this special SHA to get the onubscured diff).
The only wrinkle in this workaround is that there’s no automatic way to resolve merge conflicts on this version-that-never-existed (but logically should).
I plan to create some aliases and/or scripts to do the pr-ref-creation automatically that you’ve suggested. Thanks!
Activity
jd commentedon Aug 17, 2017
I think your analysis is right. We could probably enhance https://github.com/jd/git-pull-request to push the old ref to a random tag so it's not garbage collected though.
I've opened an issue at https://github.com/jd/git-pull-request/issues/15 just in case it's feasible and interesting.
aspiers commentedon Aug 17, 2017
@jd Thanks! Your review of #998 and #999 is also very welcome ;-)
aspiers commentedon Sep 19, 2017
Actually, the garbage-collection could be triggered not by the age of orphans, but by the number of orphans, in which case my test repository will be useless in this experiment since it has almost zero traffic.
aspiers commentedon Sep 19, 2017
A corollary of this issue is that any comments on those garbage-collected commits would also presumably be lost forever - see isaacs/github#443 (Don't lose commit-related comments on rebase).
aspiers commentedon Oct 17, 2017
I've just remembered that GitHub's UI itself explicitly admits this issue. See how after I clicked on the icon showing my review of a previous version of a PR, it presented this screen which says "Sometimes commits can disappear after a force-push":
aspiers commentedon Apr 30, 2018
@cirosantilli Please could the
pull-requestslabel (and maybe also thecode reviewlabel) be added to this?carlescufi commentedon Jun 29, 2018
+1 for this one, our project uses a rebase-driven PR approach as well. Supporting
push -fproperly so that rebased PRs display their history would be a major help for us.donquixote commentedon Jun 29, 2018
As @jd says: Tags can be a solution.
I think there needs to be a manual way to delete such tags, if you truly need to delete a commit e.g. for privacy reasons.
aspiers commentedon Jun 29, 2018
Agreed. BTW it's easy to delete tags.
Also worth noting that GitLab correctly handles this and also doesn't suffer from #998 and #999 either.
carlescufi commentedon Jun 29, 2018
It's also mentioned as a feature in https://reviewable.io/:
"Clearly shows net deltas since last time you looked, even if commits got rebased or amended"
This would be ideal, gerrit-style deltas even when you force-push.
donquixote commentedon Jun 29, 2018
Is it also easy to bulk delete tags? E.g. by wildcard?
I think a graphical UI might be useful, to let you filter the tags, then select a subset of them, then delete.
There could be different tag prefixes for "commit lost after rebase" vs "commit referred to in a github comment", so you can delete one category without deleting the other.
Auto-generated tag names could have a pattern like
archive/COMMIT_DATE/COMMIT_ID, so they don't have to be random. More parts could be added for commit author, associated branch name (if there was a branch at the time), PR or issue number.Btw one problem with auto-adding tags is that it pollutes your local repository when you
git fetch --tag. In most cases, orphan commits are not desirable to keep.aspiers commentedon Jun 29, 2018
Pollution can be avoided by using namespaces, just like Gerrit does:
https://gerrit-review.googlesource.com/Documentation/concept-refs-for-namespace.html
haochenx commentedon Oct 16, 2018
+1
This is a real problem for our team. We just migrated from Bitbucket, where they keep and display amendment history of commits. If you have commits A->B->C and e.g. amend B to B' (and thus C becomes C' with a different parent) via interactive rebase and force push the branch, the whole action will be recorded as -C -B +B' +C'. The whole action and all related commits (including B and C), as well as all review messages on those commits are retained and easily accessible from the web UI.
I personally think the Bitbucket way that is the correct way to implement regarding this issue, since a PR is supposed to be amendable and the amendment history, including any comments, are valuable for historical accounts.
KaelWD commentedon Nov 21, 2018
I'd consider this resolved, the test commit is still visible, and force pushes are now shown in the PR history

aspiers commentedon Nov 22, 2018
@KaelWD It is not necessarily resolved. As I already mentioned, my test commit experiment is very far from definitive, plus GitHub's UI explicitly admits it's an issue. The fact that force-pushes are now displayed does not guarantee that they will resolve to anything useful.
The only way we can know for sure if this is resolved is if GitHub announces they've fixed it. If noone sees a single instance of the problem in the next few months then yeah maybe it's fixed, but even then there is no way to be sure.
aspiers commentedon Nov 22, 2018
Having said that, the enhancement you spotted does resolve #998, and partially resolves #999 too, so thanks a lot for reporting it!
lvella commentedon Apr 5, 2021
Just faced this issue in a corporate instance of GitHub: It deleted the previous commit after a forced push, and it couldn't even find the original commit after I pushed it to a different branch.
xnlcasad commentedon Aug 25, 2021
@aspiers Do you know if there are any open items/discussions related to #997, #998, #999 in the https://github.com/github/feedback repository ?
I'd like to know what's the current status on supporting forced-pushed PR branches on Github. Thanks!
aspiers commentedon Aug 25, 2021
I don't know; there is supposed to be an official migration as per #1985 but GitHub seem to have gone quiet on that front for now.
aspiers commentedon Aug 25, 2021
However I have just created a new
github/feedbacklabel which we'll use to mark issues which are already reported in https://github.com/github/feedback, so in future you should be able to use that to track issues which are in both repos.erikeckhardt commentedon Aug 26, 2021
GitLab does this well, offering a great UI for selecting which two inter-revision diffs in a PR you want to see the changes between. Not sure why GitHub doesn't see this as a valuable and important feature.
aspiers commentedon Aug 26, 2021
@erikeckhardt I believe you are discussing #999 rather than this issue.
eeckhardt-chwy commentedon Aug 27, 2021
It seems you are correct as far as the UI portion. My mistake!
For the functionality portion, this case #997 does seem like a prerequisite to such a UI working. Not garbage-collecting PR commits from history, despite them being technically "unreachable" from any branch, would at least allow the "force pushed" link in the Conversation log to work, which would provide a UI of some kind.
For reference:
username force-pushed the
branch_name_herebranch from bfe2d5e to ad975e2 3 hours agoTheoretically, this could be pretty easily achieved by maintaining a hidden branch per PR that has all PR versions in history. Don't ever display these hidden branches to the user or let them be pulled down to git clients, and garbage collection is automatically prevented from disposing of those commits.
aspiers commentedon Aug 27, 2021
@eeckhardt-chwy commented on August 27, 2021 8:28 PM:
No worries ;-)
Yes, you're correct. That's why I filed the three issues #997, #998, and #999 in that order ;-) The later ones depend on the earlier ones.
In GitHub's backend, it probably wouldn't even need to be a branch; it could just be a ref, e.g. in the format
refs/pr/X/YwhereXis the PR number andYis the number of times the PR branch head has been updated. And this way this family of refs would even be helpful if it wasn't hidden, because it wouldn't pollute the branch list, but it would still be available for download to the local repo to aid with local history navigation. It's worth noting that GitHub clients could already choose to create refs like this, and maybe some already do.erikeckhardt commentedon Aug 28, 2021
At first I was thinking, no need for the
Ypart, because we won’t need each history entry to be at a tip. We could just add a commit each time the PR branch was force-pushed to, so long as it brought the index to the correct state. But then I realized that without the same history, the SHA would be different, which wouldn’t prevent garbage collection.But, having one ref per PR version would be additionally useful, because sometimes I want to view a diff of a history that never existed, which these entries would help build—if a PR submitter rebases an unmerged PR branch onto the target branch, and there were unpushed local changes included, then the diff between versions includes the rebased changes and obscures the submitter’s changes. While this is best solved by git clients or scripting, it can be worked around by pulling up the ref of the prior version, rebasing that onto the same ref the PR was rebased onto, and finally adding the result as another commit in the previous version’s ref (with the extra step of having to look up this special SHA to get the onubscured diff).
The only wrinkle in this workaround is that there’s no automatic way to resolve merge conflicts on this version-that-never-existed (but logically should).
I plan to create some aliases and/or scripts to do the pr-ref-creation automatically that you’ve suggested. Thanks!