情况就是这样,我有三个分支,master
,fix#1
和fix#2
,其中后两个分别修复了一个特定的错误。
问题是,我基于fix#2
fix#1
,而不是来自master的分支,所以它看起来像这样
fix#2
|
fix#1
|
master
而不是
fix#1 fix#2
| /
master
有没有简单的方法可以从fix#1
分支中删除所有fix#2
提交(实际上是一次提交)?
答案 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