3 ms·
> 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
by 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.