我的工作目录中有一些我试图丢弃的更改(重置为文件的当前索引版本),但是git checkout -- <file>
不会丢弃这些更改。我尝试手动删除文件 ( rm -r files
) 然后运行git checkout -- .
,这会再次显示文件已修改。
$ git checkout -- .
$ 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: files/Hulk.png
# modified: files/Hulk_2.png
#
no changes added to commit (use "git add" and/or "git commit -a")
运行git diff
显示文件已修改...
diff --git a/files/Hulk.png b/files/Hulk.png
index 1c256cb..1d37fe0 100644
Binary files a/files/Hulk.png and b/files/Hulk.png differ
diff --git a/files/Hulk_2.png b/files/Hulk_2.png
index 1c256cb..0717199 100644
Binary files a/files/Hulk_2.png and b/files/Hulk_2.png differ
注意:有些人说要运行git checkout .
,但是这将达到与git checkout -- .
. 这--
只是 git checkout 命令中用于区分树状/提交点与文件/路径的符号。
操作系统:OSX 10.6 Git:1.7.10.2