Hg: How to do a rebase like git's rebase

后端 未结 5 1577
小鲜肉
小鲜肉 2020-11-29 14:58

In Git I can do this:

1. Start working on new feature:
$ git co -b newfeature-123  # (a local feature development branch)
do a few commits (M, N, O)

master A---B         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 15:29

    I don't think the answers above achieve the OP's goal, which was to maintain his task branch, just rebased against a later point on the parent branch.

    Let's say I start with this graph (generated using the graphlog extension. Serious geek love for graphlog).

    @  9a4c0eb66429 Feature 3 commit 2 tip feature3
    |
    | o  af630ccb4a80 default againagainagain  
    | |
    o |  98bdde5d2185 Feature 3 branch commit 1  feature3
    |/
    o  e9f850ac41da foo   
    

    If I'm on the feature3 branch and want to rebase it off of the againagainagain commit, I understand that I would run hg rebase -d default. This has the following result:

    @  89dada24591e Feature 3 commit 2 tip 
    |
    o  77dcce88786d Feature 3 branch commit 1  
    |
    o  af630ccb4a80 default againagainagain  
    |
    o  e9f850ac41da foo  
    

    Mission accomplished? I don't think so. The problem is that when the commits on the feature3 branch were rebased on againagainagain, the feature3 branch was deleted. My commits have been moved to the default branch, which was what I was trying to avoid in the first place.

    In Git, the result would look like this:

    @  9a4c0eb66429 Feature 3 commit 2 tip
    |
    o  98bdde5d2185 Feature 3 branch commit 1 **feature3**
    |
    o  af630ccb4a80 default againagainagain
    |
    o  e9f850ac41da foo
    

    Notice that the feature3 branch still exists, the two commits are still on the feature3 branch, and not visible on default. Without preserving the task branch, I don't see how this is functionally different from a merge.

    UPDATE: I discovered the --keepbranches flag supported by hg rebase, and I'm happy to report everything is okey-dokey. Using hg rebase -d default --keepbranches, I exactly replicate the Git behavior I craved. A couple of aliases later and I'm rebasing like nobody's business.

提交回复
热议问题