git 命令之 reset 的用法

来源:互联网 发布:网络修复dns配置 编辑:程序博客网 时间:2024/05/17 10:09
如下是最新学习git 工具一些心得:

一、单独使用命令:

#清除当前commit节点之后的modify(该节点之后create的文件无法delete)
git reset --hard

#清除最后1次commit节点的提交信息(在该节点modify and create file 是无法delete的)
git reset HEAD~

#清除最后2次commit节点的提交信息(在该节点modify and create file 是无法delete的)
git reset HEAD~~

#清除该 commit-ID 之后的所有提交信息(在该节点modify and create file 是无法delete的)
git reset <commit-ID>                                  ==>等同于 git reset --soft <commit-ID>




                                                                                     图1


二、命令组合使用

#清除最后1次commit节点提交的所有信息(包含create 和 modify )
git reset --hard HEAD~                             ==>等同于 git reset --soft <前1个节点的commit-ID> && git reset --hard && git clean -df
前1个节点的commit-ID:如图1所示,"modify by B for  delete 1  line" 这一节点的commit-ID


#清除最后2次commit节点提交的所有信息(包含create 和 modify )
git reset --hard HEAD~~                             ==>等同于 git reset --soft <前2个节点的commit-ID> && git reset --hard && git clean -df
前2个节点的commit-ID:如图1所示,"a edit second modify" 这一节点的commit-ID


#清除commit-ID节点之后提交的所有信息(包含create 和 modify )
git reset --hard  <commit-ID>                     ==>等同于 git reset --soft <commit-ID> && git reset --hard && git clean -df


注意:有一种情况,当你编译过你的代码后再去执行git reset --hard HEAD~或<commit-ID>是删除不掉生成的文件的,这时还需要执行一遍 git clean -df


以前总是使用后面一种命令,现在有更简便的方法,怎么可能放着不用呢!!!!





0 0
原创粉丝点击