简体   繁体   中英

git rebase branches with complex history

I currently have the following situation (simplified).

   master            C --+-- E
                     |   |   |
   hotfix            |   D --+
                     |       |
  develop    A - B - C ----- F - G - H - I
                                     |
  feature                            + J - K - L

I want to end up with:

   master            C --+-- E ------+
                     |   |   |       |
   hotfix            |   D --+       |
                     |       |       |
  develop    A - B - C ----- F - G - | --- H - I
                                     |
  feature                            + J - K - L

How would I go about doing this in a decent git-way? Everything in feature is non-dependend on G , since everything that's editted on feature is simply in a seperate folder.

I've tried the following (while on feature ), but all these seem to leave traces of commits after F in feature :

 1. git rebase --onto master develop feature
 2. git rebase --onto E J~1
 3. git rebase --onto master develop

Cherry pick J,K,L from feature onto master branch. You should use a good branching strategy in the future. I'm using this one and it works pretty well.

Since I could not wait any longer for a thorough solution, I decided to use the cherrypick suggestions. Though, I did not want to go ahead and cherrypick straight on the master branch, that would be bad practice in my git flow workflow. So I did the following:

  1. Start a new hotfix

     $ git flow hotfix start vx.xx 
  2. Cherry-pick the commits from feature

     $ git cherry-pick J^..L 
  3. Finish the hotfix, essentially merging the cherry-picked commits into master and develop

     $ git flow hotfix finish vx.xx 
  4. Make sure I never get to merge the commits from the old feature branch by deleting them locally and potentially on origin .

     $ git branch -d feature $ git push origin :feature 

So, after this, I got the following:

master            C --+-- E --+---------- O
                  |   |   |   |           |
hotfix            |   D --+   J - K - L --+
                  |       |               |
develop   A - B - C ----- F - G - H - I - M

I'm still convinced I should've been able to solve this somewhat more elegantly with rebase, but I think this did the trick on a marginally elegant way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM