Easiest way to split a change set in mercurial

22,062

Solution 1

You're correct that there's no git-style index. You can use hg record (distributed with Mercurial) or hg crecord. Both let you choose on a per-file or per-hunk basis when committing. crecord is a more sophisticated, but requires curses.

UPDATE (2016-11-19)

The functionality of the crecord extension now is available in core Mercurial. Also the usage is better integrated. The preferred way to commit selected hunks is

$ hg commit --interactive

By default this behaves like the old record command. To get the curses based interface like in the old crecord command, set this in your HGRC:

[ui]
interface = curses

Solution 2

There are two ways to split a changeset, depending on whether or not you've already committed the changes that you wish to split:

To selectively commit changes from your working directory (if you haven't committed your changes yet):

  • Use hg record. (This is similar to using git commit --patch.)

To split an existing changeset (if you've already committed your changes):

  1. Use hg histedit and select the edit option on the changeset you want to edit. (This is similar to using git rebase -i.)

  2. Use hg record to selectively commit your changes as separate changesets.

  3. Use hg histedit --continue when you're done. The remaining uncommitted changes will be included in a final changeset.

As others have mentioned, you can use hg crecord in the place of hg record.

Solution 3

You might be interested to read this article that explains how another mercurial extension, patch queues, are like git's index on steroids:

http://stevelosh.com/blog/2010/08/a-git-users-guide-to-mercurial-queues/

Share:
22,062
Kurt Harriger
Author by

Kurt Harriger

Updated on February 23, 2020

Comments

  • Kurt Harriger
    Kurt Harriger over 4 years

    I'm comfortable using git, but have been exploring Mercurial lately out of curiosity based on a friends opinion that it is better in some ways.

    One of the first things I noticed however is that Mercurial does not appear to have an index as git does. I tend to make more changes then I should sometimes and after editing the file I will use git add -p to split the patch into separate commits. If the changes are in different files I could probably use MQ, but otherwise it looks like I need to undo changes first.

    Is there maybe an extension for Mercurial that provides index-like functionality?