git reset --hard和git revert命令
git誤操作時可以用git reset –hard 去撤銷這次修改,
但是這樣做也有問題,可能在之前本地有沒有提交的修改也都消失了,這種情況下,可以嘗試git revert命令。
一 git reset的使用
reset是指將當前head的內容重置,不會留任何痕跡。 Sets the current head to the specified commit and optionally resets the index and working tree to match. git reset --hard HEAD~3 //會將最新的3次提交全部重置,就像沒有提交過一樣 reset命令的--sof,--mixed,--hard 參數,會對working tree和index和HEAD進行重置
二 git revert的使用
revert是撤銷某次提交,但是這次撤銷也會作為一次提交進行保存(這樣就不會丟失原來修改過,但是沒有提交的內容)
git revert HEAD 撤銷前一次 commit git revert HEAD^ 撤銷前前一次 commit git revert commit (比如:fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff)撤銷指定的版本,撤銷也會作為一次提交進行保存。