问题描述
当你改乱了工作区某个文件的内容,还没有进行git add .
加入缓存区操作的时候。
想直接丢弃工作区的修改时,用命令git checkout -- file
进行撤销修改。
首先查看工作区的文件修改情况
使用git status
可以查看工作区的文件修改情况,如下:
$ git status
On branch machine_unit/machine-unit-list
Your branch is up to date with 'origin/machine_unit/machine-unit-list'.
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: apps/machine_unit/views.py
modified: "docs/Chapter7/\346\234\272\347\273\204\345\210\227\350\241\250\347\232\204\345\237\272\346\234\254\351\200\273\350\276\221.md"
modified: templates/base_tpl/base-list-commom.html
no changes added to commit (use "git add" and/or "git commit -a")
可以看到修改了三个文件。
撤销文件的修改,删除工作区域内容
# 首先撤销第一个文件的修改
$ git checkout -- apps/machine_unit/views.py
# 使用git status进行确认
$ git status
On branch machine_unit/machine-unit-list
Your branch is up to date with 'origin/machine_unit/machine-unit-list'.
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: "docs/Chapter7/\346\234\272\347\273\204\345\210\227\350\241\250\347\232\204\345\237\272\346\234\254\351\200\273\350\276\221.md"
modified: templates/base_tpl/base-list-commom.html
no changes added to commit (use "git add" and/or "git commit -a")
# 继续撤销下面的两个文件
$ git checkout -- docs/Chapter7/机组列表的基本逻辑.md
$ git checkout -- templates/base_tpl/base-list-commom.html
# 查看已经清除感觉工作区域了。
$ git status
On branch machine_unit/machine-unit-list
Your branch is up to date with 'origin/machine_unit/machine-unit-list'.
nothing to commit, working tree clean
网友评论