Mercurial cherry picking changes for commit

后端 未结 10 1372
长情又很酷
长情又很酷 2020-12-01 01:15

Say, I made many changes to my code and only need to commit a few of those changes. Is there a way to do it in mercurial? I know that darcs has a feature like t

10条回答
  •  长情又很酷
    2020-12-01 02:01

    I feel like I'm missing something because nobody has suggested this already.

    The normal "hg commit" command can be used to selectively choose what to commit (you don't have to commit all pending changes in the local working directory).

    If you have a set of changes like so:

    M ext-web/docroot/WEB-INF/liferay-display.xml
    M ext-web/docroot/WEB-INF/liferay-portlet-ext.xml
    M ext-web/docroot/WEB-INF/portlet-ext.xml
    

    You can commit just two of those changes with...

    hg commit -m "partial commit of working dir changes" ext-web/docroot/WEB-INF/liferay-display.xml ext-web/docroot/WEB-INF/liferay-portlet-ext.xml
    

    Not super convenient from the command line because you have to hand-type the files to selectively commit (vs a GUI check-box process like tortoise) but it's about as straightforward as it gets and requires no extensions. And file-globbing can probably help reduce typing (as it would above, both committed files uniquely share "liferay" in their pathnames.

提交回复
热议问题