views:

27

answers:

2

Let's say that I'm working on a project, with files A, B, and C. I get halfway through adding a feature, modifying A and B, before I realize that something needs cleaning. Because of the circumstances, it's optimal to interrupt the feature work to do the cleaning. This involves making changes in A, B, and C.

After I'm done with the feature, I want to check in my code. There are two different sets of changes, so to speak: those for adding the feature, and those for the cleanup. They do not conflict in any way. Is it possible to commit these changes separately, for a clean repo history?

Alternatively, what if I decided to check in the cleanup as soon as I was done with it, but didn't want to check in the halfway-completed feature in A and B?

I'm not sure if it's possible to do this in Mercurial or SVN, but I am interested in learning about either. (What about TortoiseHg?)

+3  A: 

Yes, you can do this with Mercurial's hg record. It's considered an extension, but it's distributed with the regular package. Basically, you run that command, and it asks you about each file (do you want to commit anything from here?). If you say yes, it asks you whether you want to commit each hunk (group of lines). You can also run it on particular files. E.g.:

hg record A B C

In that case, it won't bother asking you about changes to to other files.

The options for each hunk are:

y - record this change
n - skip this change

s - skip remaining changes to this file
f - record remaining changes to this file

d - done, skip remaining changes and files
a - record all changes to all remaining files
q - quit, recording no changes

? - display help

EDIT: TortoiseHg has an integrated feature called Change Selection, which is basically a GUI equivalent of record.

Matthew Flaschen
+1  A: 

The crecord extension provides a nice curses interface that lets you select exactly what pending changes you want to commit.

sth
Interesting. How does that integrate with TortoiseHg?
Rosarch
@Rosarch: It doesn't.
sth