(This is not an ideal first post of 2009, but it will have to do.)
I've noticed that people with hg tend to do backouts using "hg backout", because, well, it's a command named "backout". However, what this actually does is it places the inverse of the given commit as a child of it. Then, you have to merge the two heads to actually get the backout onto the mainline tip.
This works, but it leaves lots of turds in the commit history, and especially lots of commits with the uninteresting comment "merge": except these commits are the ones that actually get the backout into shape on the trunk! If fixups were needed as part of the merge, this makes it much more difficult to reland the patch later on if necessary.
Instead, I suggest that we do backouts essentially manually; for example, if you want to back out commit 5:
hg export 5 | patch -R -p1 ... fix up any patch failures ... hg commit -m "Backing out bug 12345, changeset abcd1234"
This leaves the history clean, and allows someone to reverse the backout by performing the same operation again.
If the commit is complex (has binary data or adds, moves, or removes files), the above won't work as intended, unless someone can find me a patch that can apply git-format patches with -R. For those cases, you should still use backout, or fix up the additions/removals manually by examining hg status (or hg addremove on a clean tree).
Happy backing out!
long live ‘bzr uncommit’
(try ‘bzr rocks’ once)
I support this.
Doesn’t moco pay various people to work on hg? It seems like me like this would be trivial to implement as a command-line flag for hg backout (fixing the complex-patch issue along the way), and it would save people from remembering what to type.
Well, obviously git-apply can apply git-format patches in reverse. Actually, git-apply is better than patch in many ways; not least is that it won’t modify any files until it’s verified that the patch will apply cleanly. If Mercurial is using the Git patch-interchange format, I’d be very surprised if it doesn’t come with the basic tools for working with that format.
Yeah, 1 to getting this built into Mercurial. I hate the merge turds, though it is nice to be able to use the same command in any situation.
-R as a parameter for hg import would make this a piece of cake.
I started off doing hg backouts using hg export|patch -Rp1, but after the first time I screwed up a backout that involved adding/removing files, I decided it wasn’t worth the risk.
I guess writing a script that will take a patch and reverse all the operations in it (e.g. replace by -) shouldn’t be too hard – and the resulting patch can be applied via “hg import” then. Using “hg export|patch -R” is really too risky for my taste.
hg doesn’t provide bidirectional binary git diffs, so git-apply –reverse won’t help you there, as I found out the hard way. You could always try combining backout, export and rollback to generate a reverse diff.