how to squash commits

Ondrej Certik ondrej at certik.cz
Sat Apr 11 18:27:46 CDT 2009


Hi,

on the numpy list, we were comparing hg and git a bit, so I played
with mercurial branches a bit, could someone good at mercurial please
go over it and correct me, if I did something stupid?

It's how I work with git, so I wanted to do the same in mercurial.
Also please don't feel offended by some my remarks, it's not personal.

Try this:

hg clone http://hg.sympy.org/sympy-git.hg
cd sympy-git.hg
hg branch new2
vim README  # do some changes
hg ci
hg up -C default
hg vi

and the hg vi doesn't even show your branch names and which branch
contains what (gitk does that).

let's edit README in the default branch:

vim README
hg ci

now if you do:

hg vi

it shows the new2 branch, and it shows the main branch diverged, so it
doesn't look as nice as in gitk, but it is possible to use. Now let's
try mercurial rebase:

$ hg up -C new2
$ hg rebase -d default
merging README
saving bundle to /tmp/ab/hg/sympy-git.hg/.hg/strip-backup/536215160a1c-temp
adding branch
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
abort: 00changelog.i at 536215160a1c: no node!


Oops, something went wrong. But commits are still there, so I guess I
can safely ignore the error message (could someone clarify?).

Now let's say I would like to merge the top two patches, since they
both modify readme and I would like to only send one patch. In git, I
just do "git rebase -i HEAD~2" tell it in vim which patches to squash
and I am done (it also asks for the new log). In mercurial, it's a
hell of a job:

$ hg qimport -r tip
$ hg qimport -r qparent
$ hg qpop
now at: 2146.diff
$ hg qfold 2147.diff
$ hg qdelete -r qbase:qtip

And I am still not done! I forgot to change the log (git asks you this
automatically during the rebase), so we need to import the patch to MQ
again:

$ hg qimport -r tip
$ hg qrefresh -e
$ hg qdelete -r qbase:qtip


And I am finally done.  Is there some easier way to do it?


Now let's say some of the patches in MQ didn't
apply after changing the order (it's usually not the case, but could
be) or some other changes. Then I am in
deep troubles, because "hg qpush" fails and I need to modify the patch
by hand (that really sucks!) -- is there some easier way? Also I need
to change the order manually in .hg/patches/series and you can easily
break it, as I did in this blogpost:

http://ondrejcertik.blogspot.com/2008/08/i-am-switching-from-mercurial-to-git.html

Besides, rebase nor MQ is enabled by default in Ubuntu Jaunty. This is
imho a showstopper, if the user not only has to do all the commands
above, but also enable them by hand, e.g. it's not part of mercurial
by default.

With git, you only use rebase (which is part of standard distribution
of git), and
rebase is pretty powerful tool that can handle most of the conflicts
itself, and if it can't, it asks you to resolve it, I assume just like
mercurial rebase, but unfortunately mercurial rebase can't be used to
mangle patches or history (correct me if I am wrong).


Any feedback (especially critical) is welcome.

If I find time, I'll then collect all the feedback and blog about it.

Thanks,
Ondrej


More information about the Mercurial mailing list