Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
782 views
in Technique[技术] by (71.8m points)

version control - Mercurial (hg) commit only certain files

I'm trying to commit only certain files with Mercurial. Because of of hg having auto-add whenever I try to commit a change it wants to commit all files. But I don't want that because certain files are not "ready" yet.

There is

hg commit -I thefile.foo

but this is only for one file. The better way for me would be if I can turn off auto-add as in Git. Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can specify the files on the command line, as tonfa writes:

$ hg commit foo.c foo.h dir/

That just works and that's what I do all the time. You can also use the --include flag that you've found, and you can use it several times like this:

$ hg commit -I foo.c -I "**/*.h"

You can even use a fileset to select the files you want to commit:

$ hg commit "set:size(1k - 1MB) and not binary()"

There is no setting that will turn off the auto-add behavior and make Mercurial work like Git does. However, the mq extension might be of interest. That's an advanced extension, but it allows you do to

$ hg qnew feature-x     # create new patch
$ hg qrefresh -s foo.c  # add a file to the current patch
$ hg qrefresh -s bar.c  # add another file to the patch
$ hg qfinish -a         # convert applied patches to normal changesets

I don't really use MQ for this purpose myself, though, since I think it's enough to just specify the filenames on the command line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...