有没有办法将一组连续的提交从一个(本地)分支移动到另一个?我已经搜索了很多,仍然没有找到明确的答案,我想要做什么。将一组连续的提交从一个(本地)分支移动到另一个
例如,说我有这样的:
master A---B---C \ feature-1 M---N---O---P---R---Q
和我已经决定了最后3个提交会更好这样的:
master A---B---C \ feature-1 M---N---O \ f1-crazy-idea P---R---Q
我知道我能做到这一点,它的工作:
$ git log --graph --pretty=oneline (copying down sha-1 ID's of P, R, Q) $ git checkout feature-1 $ git reset --hard HEAD^^^ $ git checkout -b f1-crazy-idea $ git cherry-pick <P sha1> $ git cherry-pick <R sha1> $ git cherry-pick <Q sha1>
我希望,而不是会有一个更浓ise的方式来做到这一点,可能与git rebase,虽然我没有太多的运气。
任何有识之士将不胜感激。
感谢,
杰米
一般答案(在这种简单情况下不需要)需要一个'rebase --onto':http: //stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch/1994491#1994491或http://stackoverflow.com/questions/ 2369426/how-to-move-certain-commitits-to-another-branch-in-git/2369516#2369516或http://stackoverflow.com/questions/2100851/how-to-undo-a-commit-and- commit-the-changes-into-the-other-branch-in-git/2100953 – VonC 2010-04-12 04:08:37