如果需要撤銷最近一次提交的代碼
已經commit,沒有submit狀態:可以使用git reset --hard HEAD^
比如之前已經提交了五個patch,但是需要修改第三個。
第一步: 將修改的內容stash起來 git stash 第二步: 查看第三次修改,即倒數第三次 git rebase -i HEAD~3 git rebase -i master~1 #最后一次 git rebase -i master~5 #最后五次 git rebase -i HEAD~5 #當前版本的倒數第三次狀態 git rebase -i 47893off #指定的SHA位置 第三步: 將pick修改為edit,並保存退出 第四步: 將你stash起來的需要推到這個patch里面的內容釋放出來 git stash pop {0} 第五步: 正常的add, commit即可 第六步: git rebase --continue
要是提錯了,直接git reset HEAD^ 恢復到初始狀態
參考自(親測很有效): http://blog.csdn.net/sodaslay/article/details/72948722
