Mercurial move changes to a new branch

后端 未结 4 1596
滥情空心
滥情空心 2020-12-04 05:21

I have a number of changes that I committed to my local repository, but have not yet been pushed. Since on a feature is taking longer than expected, I want to swap these ch

4条回答
  •  广开言路
    2020-12-04 06:01

    I prefer the patch solution describe here by Mark Tolonen

    What I have:

    hg log -G
    
    #default branch
    @  changeset:   3:cb292fcdbde1
    |
    o  changeset:   2:e746dceba503
    |
    o  changeset:   1:2d50c7ab6b8f
    |
    o  changeset:   0:c22be856358b
    

    What I want:

      @  changeset:   3:0e85ae268e35
      |  branch:      feature/my_feature
      |
      o  changeset:   2:1450cb9ec349
      |  branch:      feature/my_feature
      |
      o  changeset:   1:7b9836f25f28
      |  branch:      feature/my_feature
      |
     /
    |
    o  changeset:   0:c22be856358b
    

    mercurials commands:

    hg export -o feature.diff 1 2 3
    hg update 0
    hg branch feature/my_feature
    hg import feature.diff
    

    Here is the state of my local repository

    @  changeset:   6:0e85ae268e35
    |  branch:      feature/my_feature
    |
    o  changeset:   5:1450cb9ec349
    |  branch:      feature/my_feature
    |
    o  changeset:   4:7b9836f25f28
    |  branch:      feature/my_feature
    |
    | o  changeset:   3:cb292fcdbde1
    | |
    | o  changeset:   2:e746dceba503
    | |
    | o  changeset:   1:2d50c7ab6b8f
    |/
    |
    o  changeset:   0:c22be856358b
    

    Now I need to delete the revisions 1 2 and 3 from my default branch. You can do this with strip command from mq's extension. hg strip removes the changeset and all its descendants from the repository.

    Enable the extension by adding following lines to your configuration file (.hgrc or Mercurial.ini):

    vim ~/.hgrc and add :

    [extensions]
    mq =
    

    And now strip this repository on revision 1.

    hg strip 1
    

    and here we are

    @  changeset:   3:0e85ae268e35
    |  branch:      feature/my_feature
    |
    o  changeset:   2:1450cb9ec349
    |  branch:      feature/my_feature
    |
    o  changeset:   1:7b9836f25f28
    |  branch:      feature/my_feature
    |
    o  changeset:   0:c22be856358b
    

    note: changesets are different but revisions are the same

提交回复
热议问题