git rebase: copy instead of moving

℡╲_俬逩灬. 提交于 2019-12-04 15:16:08

问题


My branches are:

o---o  support.2013.16
     \
      o---o---o---o---o  master
                       \
                        o---o---o  hotfix/A

I need to copy hotfix/A to support.2013.16. I'm aware of cherry-picking, but is it possible to do something like

git rebase --onto support.2013.16 master hotfix/A

but without moving a branch but copying it instead?


回答1:


Git rebase really does copy the original branch to a new one; but because it moves the branch head, it feels like a move rather than a copy. If you used git branch to add an additional branch head to the original branch, you would still have easy access to the original branch after git rebase had made the rebased copy. So in your example

git branch rebased-A hotfix/A
git rebase --onto support.2013.16 master rebased-A

leaves you with

      o---o---o  rebased-A (hotfix/A')
     /
o---o  support.2013.16
     \
      o---o---o---o---o  master
                       \
                        o---o---o  hotfix/A



回答2:


You could create a new branch:

git checkout -b hotfix/A-support hotfix/A

and rebase it instead. So you will have two branches. Maybe you may decide to drop the branch after merging it into the support branch.

Alternatively, you could rebase the hoftix/A onto the git merge-base support.2013.16 master and then you could easily merge the hotfix/A into both branches. It will give you prettier history, no duplicate commits.



来源:https://stackoverflow.com/questions/19705313/git-rebase-copy-instead-of-moving

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!