2019年8月14日 星期三

Git reset 回復尚未push的commit

昨天因為sub module還沒commit就先commit整的專案的關係,導致sub module的一個檔案卡住沒有commit出去
但因為潔癖作祟不想因為這樣一個原因新增一個commit(前天也發生過,但那次潔癖沒發作就直接新增一個commit)直覺上我還沒push應該還有救
中間發生了不小心用了revert這個功能又平白多出一個commit的窘況(revert 是在push 出去之後的挽救方法)
今天研究之後發現這種commit錯但還沒push的情況應該是要用reset來救


在visual studio 的 git 版本管控整合GUI中就有提供reset的功能
提供兩種resetreset方式
--mixed
Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
--hard
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
簡單的說--mixed是保留檔案變更,只回復commit紀錄, --hard, 是將檔案跟commit紀錄都回復到某個狀態

附錄:用visual studio GUI reset
 在想回復到的commit上按右鍵

沒有留言:

張貼留言