Take the 2-minute tour ×

Is there a mercurial equivalent of git add -p?

Quoting from man, git-add with the option -p (or --patch) does the following:


share|improve this question
Someone pointed me to mercurial.selenic.com/wiki/ShelveExtension which seems to have the same scope but attacks the problem from a different perspective (select what to put away vs select what to add). –  alieb Oct 14 '11 at 9:00
This was at least part of TortoiseHg before the new port, and is currently not implemented in the new port. See bitbucket.org/tortoisehg/thg/issue/188/… –  Lasse V. Karlsen Oct 14 '11 at 9:09
@LasseV.Karlsen: The shelve feature is still available in the latest TortoiseHg. It can be accessed via the Repository -> Shelve menu or through an icon in the commit window. –  Tim Henigan Oct 14 '11 at 13:33
add comment

3 Answers

up vote 24 down vote accepted

Have a look at the record extension (which comes bundled with Mercurial).

Note that since Mercurial doesn't have the concept of the staging area like git, running hg record will simply allow you to examine, hunk by hunk, the modifications in your working copy. Any changes you choose to record will be committed, and any changes you choose not to record are simply left as modifications in your working copy.

share|improve this answer
It is worth noting that the record extension comes bundled with Mercurial. –  Laurens Holst Oct 17 '11 at 8:28
add comment

The Record Extention is the standard tool for this. It allows you to pick hunks to include or not in a commit. Once you've enabled the extension in your hgrc, the command is just

hg record

The CRecord Extension gives you a TUI (Text User Interface) on top of this which allows you to go down to which lines you want to include. This isn't standard though, so it need downloading to a directory before you can enable it in your hgrc.

hg crecord
share|improve this answer
add comment

If you are using TortoiseHg, it has a Shelve feature which allows you to store changes you don't want to commit to a temporary area. It allows hunk selection, just like git.

In the TortoiseHg Workbench, this tool can be accessed in 2 ways:

  1. Click Repository -> Shelve
  2. In Commit window, select the shelve tool icon. It looks like this:

enter image description here

share|improve this answer
The advantage of the shelve approach is that you can test your changes before committing. –  Laurens Holst Oct 17 '11 at 8:29
+1 Laurens, It's always bugged me that when doing a 'git add -p', I'm essentially guessing what subset of changes will form a working commit, and then inputing that guess using an error-prone manual process. Asking for trouble. –  Jonathan Hartley Jun 21 '13 at 8:22
add comment

Your Answer


