Move branch to another branch

寵の児 提交于 2019-12-04 08:56:21

问题


I have started doing some work on a branch which I have in term realised was the wrong branch. Is there a way to move a branch to a different branch.

For example:

A -- B -- C -- D -- HEAD
 \-- E -- F -- G -- H -- I -- J
      \-- K -- L

And I want this:

A -- B -- C -- D -- HEAD
 \    \-- K -- L
  \
   \-- E -- F -- G -- H -- I -- J

回答1:


Let's say you've named your branches like so:

    A -- B -- C -- D (master)
     \-- E -- G -- H -- I -- J (current-parent)
          \-- K -- L (my-branch)

What you want to do is rebase my-branch onto the B commit like so:

    git rebase current-parent my-branch --onto B



回答2:


You could use git rebase --onto, e.g.,

git rebase --onto new-base old-base your-branch

So in your case, something like:

git rebase --onto B E L

should work.




回答3:


This is just the sort of thing git rebase can do.

https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html



来源:https://stackoverflow.com/questions/21459197/move-branch-to-another-branch

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