Mercurial Unstage Specific Files from the Working Directory

I have an uncommitted set of changes. I want to commit some changes, but not commit some files (e.g. uninstall the file in git). Can this be done in mercurial?

+7
source share
3 answers

Use the -X option for hg commit to exclude specific files. You can specify it more than once on the command line. For example,

 hg commit -X path/to/unwanted/file -X path/to/another/file 
+9
source

You can pass a list of files to commit to hg commit , for example. hg commit -m msg file1 file2 ...

+7
source

Oops! You have two options.

  • Commit only some files.

    If you specify file names as arguments to hg commit , only those files will be committed. Therefore, if I have the following hg status :

     M foo.txt M bar.txt 

    I can run hg commit foo.txt to commit the changes to foo.txt and leave the changes to bar.txt for later commit.

  • Use the record extension.

    A write extension gives Mercurial behavior for the git index, allowing you to commit only some fixes to your changes (e.g. git add --patch ). See the docs for more details.

+4
source

All Articles