Reputation: 2527
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?
Upvotes: 35
Views: 25551
Reputation: 284796
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
Upvotes: 24
Reputation: 6119
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):
hg record
. (This is similar to using git commit --patch
.)To split an existing changeset (if you've already committed your changes):
Use hg histedit
and select the edit option on the changeset you want to edit.
(This is similar to using git rebase -i
.)
Use hg record
to selectively commit your changes as separate changesets.
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
.
Upvotes: 50
Reputation: 3960
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/
Upvotes: 1