4 ms·
> Last friday I lost a commit using git reset --HARD (shit happens), so I decided it was time to study Mercurial?! > git again Aw. It may be interesting to
by twic 12y ago
> Last friday I lost a commit using git reset --HARD (shit happens), so I decided it was time to study
Mercurial?!
> git again
Aw.
It may be interesting to compare the safety nets that Git and Mercurial provides. Mercurial tries to steer you away from rewriting history, but it does supply a complete set of tools for doing it - it has rebase, strip, commit --amend and so on. The difference is in what happens to deleted history.
In Git, as i understand it, history is defined by the branch pointers and the commits reachable from those. Deleting history simply means fiddling the branch pointers; the underlying commits are still there, completely unchanged. But now you can only find them via the reflog (unless you wrote their hashes down or something). They will stay there until the next garbage collection cycle. I don't know what determines when garbage collection occurs, so that might be ages, or it might not be long.
In Mercurial, history is defined by the commit graph. If something is in the graph, it's in history. That means that to delete something from history, you need to actually remove it from the graph. Commits which are removed are written as bundle files to the .strip-backup directory inside the repository's .hg directory. These are compressed binary files, so they're not much fun to look at directly, and i'm not aware of any way to display their contents, but Mercurial can import them, so restoring the changes. These files are never deleted automatically.
Really, Git's safety net is more tractable - once you have identified a deleted commit, you can work with it in the same way as any other commit. Mercurial's safety net is purely cold storage. I believe this reflects the tools' different opinions on rewriting history: in Git, it's normal, so you'll need the safety net a lot, whereas in Mercurial, it's not normal, so you will only need it if you have been bad, and you should feel bad.
Fortunately, something that is slowly arriving in Mercurial is the concept of changeset evolution:
http://mercurial.selenic.com/wiki/ChangesetEvolution http://mercurial.selenic.com/wiki/ChangesetEvolution
Which basically keeps deleted commits in the tree, like Git, but marks them as deleted. Moreover, when you do things like amend or rebase, it marks commits as having been replaced by other commits. Those marks are in the committed metadata, and are propagated between repositories, which means it becomes possible to do things like safely rebase public commits, merge different attempts at rebasing some commits, and more besides. If changeset evolution works as well as is hoped, it will provide all the advantages of history mutation without any of the drawbacks, which will be super sweet.
- jordigh 12y agoSpeaking of Evolve, I would like to promote my own talk + demo about it: http://www.youtube.com/watch?v=4OlDm3akbqg http://www.youtube.com/watch?v=4OlDm3akbqg