29

Let's say you do hg status and you have three files modified. I know how to check in all three files (hg commit). But how can you check in (and then hg push) just one of the modified files?

Martin Geisler
  • 71,485
  • 25
  • 165
  • 226
Marcus Leon
  • 53,069
  • 115
  • 287
  • 420
  • 2
    possible duplicate of [Using mercurial, what's the easiest way to commit and push a single file while leaving other modifications alone?](http://stackoverflow.com/questions/125272/using-mercurial-whats-the-easiest-way-to-commit-and-push-a-single-file-while-le) – Milen A. Radev May 25 '10 at 20:29

3 Answers3

44

Please check the output of hg help commit which reveals that you can do

hg commit foo.c

if you just want to commit a single file. This is just like Subversion and many other systems — no hocus-pocus :-)

Martin Geisler
  • 71,485
  • 25
  • 165
  • 226
  • I receive a message "abort ... file not tracked!". My local repository is already tracked by Mercurial. What could be wrong? – WindRider Mar 24 '14 at 19:16
  • 1
    @WindRider: it means that you need to tell Mercurial that you want to track the file first. Use [`hg add` for that](http://www.selenic.com/mercurial/hg.1.html#add). See also [a Mercurial guide](http://mercurial.aragost.com/kick-start/en/basic/#creating-a-changeset) – Martin Geisler Mar 26 '14 at 08:21
7

Just do:

hg ci -I path/to/file -m "commited only one file"

That commits only one file, and you can push it, and none of the uncommitted changes will be affected.

Ry4an Brase
  • 77,712
  • 6
  • 146
  • 168
  • 2
    you should also be able to do it just like you would in svn: hg commit -m "here is my message" path/to/file – RyanWilcox May 25 '10 at 23:28
2

On the off chance you're running on Windows, TortoiseHG (a graphical Mercurial interface) lets you select which files to commit every time.

Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61
dimo414
  • 44,897
  • 17
  • 143
  • 228