views:

171

answers:

2

Many times I'm making two different changes to files in my repository, I want those changes to be treated as two consecutive commits.

For example, in repository

  • prog.c
  • prog.h
  • README.txt

While fixing a bug prog.c and prog.h, I fixed a typo in README.txt. Now I want to commit the change to prog.c with its own commit message, and the change to README.txt afterwards.

In git, I could easily do that with the index

git add prog.c prog.h
git commit -m 'bug #1234'
git commit README.txt -m 'some typos fixed'

What's the best way to do that in Mercurial?

Clarification: I used (before the edit) a toy example where each changeset spans over a single file. But I want the general answer, what should I do when there are many files in each changeset.

+12  A: 
hg commit -m "bug #1234" prog.c prog.h

then

hg commit -m "some typos fixed" README.txt
Jerome
What if it's more than one file for bug #1234?
Elazar Leibovich
hg commit -m "bug #1234" prog.c prog.h
Jerome
If you want all files but README.txt: hg commit -m "bug #1234" -X README.txt
Jerome
For a list of all parameters: hg help -v commit
Jerome
+1  A: 

I LOVE the crecord mercurial extension for this purpose: it gives me file by file (and chunk by chunk, and line by line) control over what exactly I want in this commit.

RyanWilcox
Or the original record extension which is shipped with mercurial and works on Windows.
pmezard