10

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.

Cœur
  • 34,719
  • 24
  • 185
  • 251
Elazar Leibovich
  • 31,610
  • 30
  • 120
  • 165
  • Does this answer your question? [Mercurial (hg) commit only certain files](https://stackoverflow.com/questions/8188605/mercurial-hg-commit-only-certain-files) – Daij-Djan Jun 01 '20 at 02:58

2 Answers2

19
hg commit -m "bug #1234" prog.c prog.h

then

hg commit -m "some typos fixed" README.txt
Elazar Leibovich
  • 31,610
  • 30
  • 120
  • 165
Jerome
  • 8,339
  • 2
  • 31
  • 41
2

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
  • 13,630
  • 1
  • 34
  • 58