但有時候難免也會在 commit 的時候不小心出一點錯
像是 "阿剛剛 commit message 寫錯了"
或者是 "WT* 這 code 根本有問題,這次 commit 重來啦"
之類的
只要還沒 push 都有得救
如果 push 了的話就不要再亂搞了,因為聽說會發生很恐怖的事情
commit message 寫錯相對好解決,只要[1]
git commit --amdne就可以修改上一次的 commit message
或者是有東西忘記 add
git add <forgotten_file1>或者用[2]
git add <forgotten_file2>
git commit --amend
git commit --amend <forgotten_file1> <forgotten_file2>...這樣可以把 forgotten files 加到上次的 commit 裡面 (覆蓋的概念)
不過這我都沒試過 @@
至於上上次或更久以前的我就不知道惹
如果要取消整個 commit,可以用 [2]
git reset HEAD^ --soft可以取消 commit 並且把修改過的檔案都留著
如果是用
git reset HEAD^ --hard的話就會取消 commit 並且把修改過的檔案都沒收 !!!
也就是再也看不到它們了 T^T
要小心使用
當然如果 code 寫爛了這當然是一個很好的處理方法
Reference
[1] http://git-scm.com/book/zh-tw/v1/Git-%E5%9F%BA%E7%A4%8E-%E5%BE%A9%E5%8E%9F[2] http://gogojimmy.net/2012/02/29/git-scenario/
No comments:
Post a Comment