Mercurial cherry picking changes for commit

后端 未结 10 1345
长情又很酷
长情又很酷 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 01:56

    I use commit-patch. It's a script that lets you edit the diff before committing. It's really nice with Emacs's diff-mode and vc-mode.

    In the past I used crecord, but it has bugs related to unicode (actually the record extension has the bugs, which crecord depends on).

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-01 02:03

    If you are using TortoiseHg 1.x for Windows, this feature is implemented beautifully right out of the box (no extensions required).

    1. Run the TortoiseHg Commit Tool.
    2. Choose a file for which you only want to commit a subset of its changes.
    3. Click on the Hunk Selection tab in the preview pane.
    4. Double-click or use the spacebar to toggle which change hunks should be included in the commit.

    For TortoiseHg 2.x, the Hunk Selection tab is now gone. In its place, is the Shelve tool. It has a few more features than the old hunk selection. Those new features come at the cost of some added complexity.

    enter image description here

    Note that there is no need to explicitly enable the Mercurial Shelve extension when using this feature. According to Steve Borho (lead TortoiseHg developer) in response to a different TortoiseHg question: "We have a local copy of the shelve extension and call into it directly."


    For TortoiseHg 2.7+, this functionality has been improved and re-introduced. It is now built directly into the Commit tool:

    example of change selection in the commit tool

    Notice in the file list on the left that the top file is checked to indicate it will be included, the second file is unchecked because it will not be included, and the third file, Sample.txt, is filled (the Null checkbox indicator) because only select changes from that file will be included in the commit.

    The change to Sample.txt that will be included is checked in the lower-right change selection portion of the image. The change that will be excluded is unchecked and the diff view is grayed out. Also notice that the icon for the shelve tool is still readily available.

    0 讨论(0)
  • 2020-12-01 02:04

    First you must forget everything you ever knew about GUI's and return to the commandline. Next from the commandline do this:

    hg stat > filelist.txt

    This pipes all your modified files into a text file called filelist.txt

    Next edit your filelist to include only the files you wish to commit.

    Finally commit using the fileset sytnax:

    hg commit "set: 'listfile:test.txt'"

    0 讨论(0)
提交回复
热议问题