git reset --hard和git revert命令

 

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)撤销指定的版本,撤销也会作为一次提交进行保存。
 
posted @ 2017-09-01 19:08  wbxjiayou  阅读(3162)  评论(0编辑  收藏  举报