How to checkout a file from one branch to another in Mercurial?

前端 未结 2 475
忘了有多久
忘了有多久 2021-02-12 11:41

How to checkout a single file from one branch to another in Mercurial?

Basically I want to copy a single file from a branch experimental to another branch

2条回答
  •  遇见更好的自我
    2021-02-12 12:19

    hg revert as suggested by @shellholic will indeed create a file from one branch in another branch. However the file will look as freshly added in history. Its actual history is not shown in the target branch.

    I find grafting a better alternative.

    Let's assume you have 2 branches, and you have created and worked on file f2.txt in the side branch. You were also working on the file f3.txt in the same branch at the same time.

    1. Create another changeset in the source (side) branch, this changeset containing only the file you are interested in. If you already have such changeset, use it, no need to create a new one.

    2. Update to the target branch.

    3. Graft the source changeset. Mercurial will ask you if you want to use the changed version. Answer "c" (changed).

    The result looks like this:

    the file history is correctly preserved:

    and f3.txt is not merged into the target branch.

提交回复
热议问题