One of import differences between Mercurial and git is that in the former it is very hard to change the history of a repository. It is by design (although it can be ,,bypassed’’ with usage of plugins like MQ) and there are good reasons for it. This gives this warm, fuzzy feeling of security and makes harder to screw up really hard. So I consider it to be a real user-friendly aspect of Mercurial.
But recently I was bitten by rollback command which undo last transaction (
pull, and some other commands). I use it more often than I would like - mostly for undoing commit. It helps when I have forgot to add a file, or added some garbage, etc. It is suitable only before pushing changes somewhere, because otherwise they will back. But in my case, many simple mistakes are spotted right away, just after
commit, and maybe
status. They may be fixed without rollback - with a second commit, but it would unnecessary clobber history and make look silly. So if I make an erroneous commit I rollback, fix it and commit again. This procedure has worked fine many, many times. Until recently.
Let see some contrived example. First we create a repo:
Next we start some development in a branch:
And next we make mistaken commit
Normally if we spot error right away we can issue:
But if we change a branch and then make a rollback we are screwed:
Since the commit is undone there is no
c in branch
update does not help. Fortunately for me, I had editor windows still opened, where I could use undo - to redo my changes. This time I have not lost anything. But there were some scary moments ;-).
So I think the lesson is that if you are to make a rollback then be sure that you have not made any updates to the repository, because rollback will not even warn you.