Rebase feature branch onto another feature branch

后端 未结 3 910
渐次进展
渐次进展 2020-11-30 16:33

I have two (private) feature branches that I\'m working on.

a -- b -- c                  <-- Master
     \\     \\
      \\     d -- e           <-- Br         


        
相关标签:
3条回答
  • 2020-11-30 16:53

    I know you asked to Rebase, but I'd Cherry-Pick the commits I wanted to move from Branch2 to Branch1 instead. That way, I wouldn't need to care about when which branch was created from master, and I'd have more control over the merging.

    a -- b -- c                  <-- Master
         \     \
          \     d -- e -- f -- g <-- Branch1 (Cherry-Pick f & g)
           \
            f -- g               <-- Branch2
    
    0 讨论(0)
  • 2020-11-30 16:54

    Note: if you were on Branch1, you will with Git 2.0 (Q2 2014) be able to type:

    git checkout Branch2
    git rebase -
    

    See commit 4f40740 by Brian Gesiak modocache:

    rebase: allow "-" short-hand for the previous branch

    Teach rebase the same shorthand as checkout and merge to name the branch to rebase the current branch on; that is, that "-" means "the branch we were previously on".

    0 讨论(0)
  • 2020-11-30 17:04
    1. Switch to Branch2

      git checkout Branch2
      
    2. Apply the current (Branch2) changes on top of the Branch1 changes, staying in Branch2:

      git rebase Branch1
      

    Which would leave you with the desired result in Branch2:

    a -- b -- c                      <-- Master
               \
                d -- e               <-- Branch1
               \
                d -- e -- f' -- g'   <-- Branch2
    

    You can delete Branch1.

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