2014年1月8日 星期三

不小心 git commit --amend 了別人的 patch

環境

2d14654 HEAD@{0}: commit (amend): Other's patch
428555b HEAD@{1}: commit: Other's patch
bd33767 HEAD@{2}: commit: Previous one

先把 HEAD 退回到原來的 patch, 記得確定把你的 working directory 搞乾淨

$ git reset --hard HEAD~1
HEAD is now at bd33767 Previous one

$ git cherry-pick 428555b
....

把 amend 到別人 patch 的內容 diff 出來,重新 apply, apply 的參數 - (dash) 表示是從 STDIN 讀入

$ git diff 428555b 2d14654 | git apply -

這時打 git status 就可以發現當初的修改回來 unstage 的狀態了, 重新 git commit

$ git commit

完成