如何更改当前分支的分支?

时间:2011-11-24 11:36:35

标签: git branch git-branch

情况就是这样,我有三个分支,masterfix#1fix#2,其中后两个分别修复了一个特定的错误。

问题是,我基于fix#2 fix#1,而不是来自master的分支,所以它看起来像这样

fix#2
|
fix#1
|
master

而不是

fix#1  fix#2
|     / 
master 

有没有简单的方法可以从fix#1分支中删除所有fix#2提交(实际上是一次提交)?

1 个答案:

答案 0 :(得分:2)

git rebase --onto master fix1 fix2

但在你做之前,请确保你了解会发生什么以及所有后果。

git rebase -h输出:

Usage: git rebase [--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]

git-rebase replaces <branch> with a new branch of the
same name.  When the --onto option is provided the new branch starts
out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
It then attempts to create a new commit for each commit from the original
<branch> that does not exist in the <upstream> branch.

It is possible that a merge failure will prevent this process from being
completely automatic.  You will have to resolve any such merge failure
and run git rebase --continue.  Another option is to bypass the commit
that caused the merge failure with git rebase --skip.  To restore the
original <branch> and remove the .git/rebase-apply working files, use the
command git rebase --abort instead.

Note that if <branch> is not specified on the command line, the
currently checked out branch is used.

Example:       git-rebase master~1 topic

        A---B---C topic                   A'--B'--C' topic
       /                   -->           /
  D---E---F---G master          D---E---F---G master
相关问题