混帐:如何某些提交移动到新的分支
问题描述:
我在直线一直在努力:混帐:如何某些提交移动到新的分支
A---B---C---D---E---F (master:HEAD)
现在我想向后移动:
git checkout C
和移动一些最后提交到一个新的分支:
选项1:
D---E---F (new:HEAD)
/
A---B---C (master)
选项2:
F (new:HEAD)
/
A---B---C (master)
如何重定向到选项1以及如何选项2?
答
要从第一图(主= HEAD = F)到达选项1:
git branch new # Make a 'new' branch pointing at HEAD, which is F
git reset --hard C # Move master back to point at C
git checkout new # Make HEAD follow new, and get F in the working tree
而从选项1至选项2(拿起其中上述左关闭),
git rebase -i master # Start the process of re-jiggering this branch
# edit the commit list that opens up to only include F
# save and exit
# resolve potential conflicts from missing changes in D and E
要直接从您的出发点去选择2:
git checkout -b new C # Start the 'new' branch at C
git cherry-pick F # Include F on it
git checkout master # Switch back to master
git reset --hard C # Rewind master to the earlier commit
感谢这个详细的解答。 – takeshin 2010-07-02 19:19:32
谢谢:)另外,为“重新jiggering”+1! – dokkaebi 2012-12-21 22:54:58
如果在尝试推送主服务器时出现错误“更新被拒绝,因为当前分支的提示位于其远程对象的后面”,则需要使用--force选项:'git push --force origin master' – Tamlyn 2013-02-27 11:18:17