撤销修改 - morris131/morris-book GitHub Wiki
- 将版本库的内容撤回到工作区 git checkout -- readme.txt
- 修改readme.txt
git is a version control system.
git is free software under the GPL.
git tracks changes of files.
this is a error.
$ git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a") 2) 撤回
$ git checkout -- readme.txt
$ cat readme.txt
git is a version control system.
git is free software under the GPL.
git tracks changes.
- 将暂存区的内容撤回到工作区 git reset HEAD readme.txt
- 修改readme.tx
git is a version control system.
git is free software under the GPL.
git tracks changes.
this is a error.
$ git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a") 2) 提交readme.txt
$ git add readme.txt
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
modified: readme.txt
- 撤销暂存区的修改
$ 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 ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a") 4) 撤销工作区的修改
$ git checkout -- readme.txt
$ git status
On branch master
nothing to commit, working directory clean