4 ms·
This sounds like the wrong solution to me. The problem isn't (or rather, is rarely[1]) that you've "polluted" a public branch with bad code. Bad code gets pus
by ajross 11y ago
This sounds like the wrong solution to me. The problem isn't (or rather, is rarely[1]) that you've "polluted" a public branch with bad code. Bad code gets pushed into branches by perfectly legal commits all the time, and you fix it via software engineering and not administrative policy.
The real problem with the accidental force push is that it's lossy. The OLD head, to which you would hope to revert when you realize your mistake, is suddenly invisible (and garbage-collectible!).
So I'd much prefer to see github fix this with a "hard reflog" of the branch state on the server. Track the head of each branch at each point in "monotonic server time" (with a tag or whatnot, or even outside the repository would be fine) such that you can always (1) detect force push events like this and (2) trivially revert them.
[1] Yeah, occasionally you might push your site keys, or some NDA-covered source code. And in those situations you want the reverting push to actually "forget" the code. But that should be the rare exception and not the standard process.
- sampo 11y ago> The real problem with the accidental force push is that it's lossy. The OLD head, to which you would hope to revert when you realize your mistake, is suddenly invisible (and garbage-collectible!). I prefer how Mercurial behaves in this matter. A push can not destroy old heads, and the old (dangling) heads still show up in the log by default (you can filter them out with an option, if you don't want to see them). So if someone pushes a new head by accident, anyone can still see what is going on, and fix the situation either by a merge, or reverting back to the old head. (The downside is, if everyone really knows what they are doing and never make mistakes, git's way of deleting old heads with just a force push is easier, than needing to specifically access the repo on a server if you want to delete some heads.)
- masklinn 11y agoTechnically a push does not destroy heads in git either (that requires a gc), but contrary to mercurial "detached heads" are not visible by default, you have to explicitly go and hunt for them.
- sampo 11y agoYes, you are correct. The problem is not so much with git, it is with GitHub. You cannot retrieve dangling heads from GitHub, not even by cloning. Maybe GitHub runs garbage collection right away? But if you just keep your repositories on your computers, then yes, you can clone and then find the dangling commits in the clone, too, and then save them.
- masklinn 11y ago> You cannot retrieve dangling heads from GitHub, not even by cloning. Maybe GitHub runs garbage collection right away? Nah, since you can undelete branches on github. It's just the way git works: it only retrieves (clone/fetch) named heads and whatever is reachable from there, so detached heads aren't fetchable.
- nsfyn55 11y ago> Track the head of each branch at each point in "monotonic server time oof talk about over-engineering. What is the point? Just don't allow force pushes to protected branches is a much simpler model than. "Keep a bunch of bookkeeping meta data in the event of an unanticipated force push". All this complexity would only save you during the span of time those objects were collectible but not yet collected.
- ajross 11y agoNot really following your point. What I described could be implemented by a post-update hook that just ran "git rev-parse HEAD" and stuffed the result into a database somewhere. If anything it's significantly easier to implement than an authorization model.
- nsfyn55 11y agoI'm not following where you are going. If these database records point to objects in the git database. How will you synchronize garbage collection and the state of the database?
- ajross 11y agoWith pointers out of the refs directory, the way you do it for everything else? Are you deliberately trying to start a fight? This isn't a complicated subject...
- nsfyn55 11y agoNot trying to start a fight, I just don't understand your solution. What does git do with orphaned entries in the refs directory when it garbage collects? Does it delete them? How would you synchronize your database pointers with garbage collection? Presumably when this happened you'd have to interrupt it or you'd have to delete those records from your database. Then they'd really be lost right?