git 将分支移动到另一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21459197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Move branch to another branch
提问by user204088
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
回答by Wolf
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:
你想要做的是my-branch
像这样rebase到 B 提交:
git rebase current-parent my-branch --onto B
回答by adamdunson
You could use git rebase --onto
, e.g.,
你可以使用git rebase --onto
,例如,
git rebase --onto new-base old-base your-branch
So in your case, something like:
所以在你的情况下,类似于:
git rebase --onto B E L
should work.
应该管用。
回答by Peter Westlake
This is just the sort of thing git rebase
can do.
这正是git rebase
可以做的事情。
https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html
https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html