git 错误操作回滚
2015-11-27 17:23
197 查看
回滚范例:
1.初始化并操作文件
$ git init //初始化
$ touch foo.txt //创建foo.txt文件,待提交git
$ git add foo.txt //git add文件
$ git commit -m "initial commit” //添加commit注释
$ echo 'new data' >> foo.txt //第一次修改文件
$ git commit -a -m "more stuff added to foo” //添加commit注释
2.查看提交记录
$ git log
* 98abc5a (HEAD, master) more stuff added to foo
* b7057a9 initial commit
3.模拟误操作重置状态
$ git reset --hard b7057a9
$ git log
* b7057a9 (HEAD, master) initial commit
NOTE:虽然已经在git log中看不到之前的head,但是reflog记录了你此前的操作。记录了所有head的修改历史。
4.查看Reflog
$ git reflog
b7057a9 HEAD@{0}: reset: moving to b7057a9
98abc5a HEAD@{1}: commit: more stuff added to foo
b7057a9 HEAD@{2}: commit (initial): initial commit
5.回滚丢失的head:
$ git reset --hard 98abc5a
6.再次查看git log 验证
$ git log
* 98abc5a (HEAD, master) more stuff added to foo
* b7057a9 initial commit
只要按照以上步骤,一般都可以正常回滚。除非你的错误操作被当做rubish丢弃了。理论上讲30天内reflog不会被清空。
1.初始化并操作文件
$ git init //初始化
$ touch foo.txt //创建foo.txt文件,待提交git
$ git add foo.txt //git add文件
$ git commit -m "initial commit” //添加commit注释
$ echo 'new data' >> foo.txt //第一次修改文件
$ git commit -a -m "more stuff added to foo” //添加commit注释
2.查看提交记录
$ git log
* 98abc5a (HEAD, master) more stuff added to foo
* b7057a9 initial commit
3.模拟误操作重置状态
$ git reset --hard b7057a9
$ git log
* b7057a9 (HEAD, master) initial commit
NOTE:虽然已经在git log中看不到之前的head,但是reflog记录了你此前的操作。记录了所有head的修改历史。
4.查看Reflog
$ git reflog
b7057a9 HEAD@{0}: reset: moving to b7057a9
98abc5a HEAD@{1}: commit: more stuff added to foo
b7057a9 HEAD@{2}: commit (initial): initial commit
5.回滚丢失的head:
$ git reset --hard 98abc5a
6.再次查看git log 验证
$ git log
* 98abc5a (HEAD, master) more stuff added to foo
* b7057a9 initial commit
只要按照以上步骤,一般都可以正常回滚。除非你的错误操作被当做rubish丢弃了。理论上讲30天内reflog不会被清空。
相关文章推荐
- RPC failed; result=22, HTTP code = 411
- git更新已經刪除的文件
- 提取Git每次提交后Commit的文件
- GIT迁移服务器
- 分布式版本管理git入门指南使用资料汇总及文章推荐
- Git远程操作详解
- 25个 Git 进阶技巧(翻译)
- 详解版本控制利器Git,SVN的异同以及适用范围
- Ruby实现的删除已经合并的git分支脚本分享
- 在 Shell 提示符中显示 Git 分支名称的方法
- Git使用基础篇(一些常用命令和原理)
- git fork同步是什么意思?
- Git使用小坑 Out of memory错误的解决方法
- Python的高级Git库 Gittle
- 使用GIT进行源码管理――GUI客户端小结
- 使用git代替FTP部署代码到服务器的例子
- linux系统安装git及git常用命令
- 分享下自己总结的Git常用命令
- Git 常用命令速查表(图文+表格)
- mac git xcrun error active developer path 错误