要從第一圖(主= 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