$ cat readme.txt
git is a version control system
git is free software
编辑readme.txt文件,添加一行内容,如下
$ cat readme.txt
git is a version control system
git is free software
append a new line
然后,我们查看状态
$ 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
`Changes are not staged for commit:`说明工作区有了修改,却没有添加(statged)到暂存区
`modified: readme.txt` 说明修改的文件为readme.txt
接下来,我们使用命令来撤消工作区中的修改
$ git checkout -- readme.txt
然后,我们再用`git status`命令来查看状态
$ git status
# On branch master
nothing to commit, working directory clean
可以看出,工作区是干净的(working directory is clean),即工作区的修改已经被撤消了
撤消暂存区的修改
假设learngit仓库下有一个readme.txt文件,内容如下
$ cat readme.txt
git is a version control system
git is free software
编辑readme.txt文件,添加一行内容,如下
$ cat readme.txt
git is a version control system
git is free software
append a new line
然后,把修改添加到暂存区
$ git add readme.txt
此时,查看状态
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: readme.txt
#
`Changes to be committed:` 说明修改已经添加到暂存区了,等待被commit
接下来,执行`git reset HEAD`命令来撤消暂存区的修改,重新放回工作区
$ git reset HEAD readme.txt
Unstaged changes after reset:
M readme.txt
再来查看状态
$ 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")