廖雪峰Git教程笔记(八)撤销修改
2018-01-14 20:05
591 查看
假设,假设,不过现在是凌晨两点,你正在赶一份工作报告,你在readme.txt中添加了一行:
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. My stupid boss still prefers SVN.
还好没有提交,现在,看一下status和diff
git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: readme no changes added to commit (use "git add" and/or "git commit -a")
git diff readme diff --git a/readme b/readme index a9c5755..533f857 100644 --- a/readme +++ b/readme @@ -2,3 +2,4 @@ Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. +My stupid boss still prefers SVN.
从status看出,git checkout – file可以丢弃工作区修改
git checkout -- readme
这里git checkout – readme意思是,把readme文件在工作区的修改全部撤销,有两种情况:
一种是readme自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态。
一种是readme已经添加到暂存区后,又做了修改,现在,撤销修改就回到添加到暂存区后的状态
总之,就是让这个文件回到最近一次git commit 或git add时的状态。
现在内容已经恢复了。。。
现在假定是凌晨3点,你不但写了一些胡话,还git add到暂存区了:
Git is a distributed version control system. Git is free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. My stupid boss still prefers SVN.
git add readme
查看一下状态
git status readme On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: readme
从暂存区中撤销
git reset HEAD readme Unstaged changes after reset: M readme
再从工作区中撤销
git checkout -- readme
完成。。。。
小结:使用reset HEAD file可以从暂存区中撤销,使用git checkout – file 可以从工作区中撤销
相关文章推荐
- 跟着廖雪峰的git教程学习(2)时光机穿梭(四)撤销修改
- 廖雪峰Git教程笔记(七)管理修改
- 廖雪峰的Git教程六-撤销修改
- 【Git学习笔记】撤销修改
- git教程2(版本回退、管理修改、删除文件)——廖雪峰老师
- Git-撤销修改(笔记)
- 廖雪峰Git教程笔记(十七)Bug分支
- 廖雪峰Git教程笔记(二十四)使用码云
- Git版本控制教程 - Git查阅、撤销修改和版本回退
- Git学习笔记(3)——撤销修改与文件删除
- 廖雪峰Git教程笔记(十一)添加远程库
- 【GIT-2】GIT 的基础教程 工作区暂存区,修改,撤销,删除 远程仓库
- [笔记1]---廖雪峰老师的Git教程
- git整理——廖雪峰教程笔记
- Git学习笔记 chapter04--撤销修改和删除文件
- git教程4------撤销修改
- 廖雪峰老师git教程笔记(1)
- 廖雪峰Git教程学习笔记。持续更新中。。。
- git笔记 (根据廖雪峰git教程整理)
- Git学习笔记(3)——撤销修改和文件的删除