您必须指定错误的提交或错误的路径。
$ git init
Initialized empty Git repository in /.../.git/
$ echo test.txt > .gitignore
$ git add .gitignore
[master (root-commit) 6ed8815] Commit 1
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
$ git commit -m "Commit 1"
$ echo 'Version 1' > test.txt
$ git add test.txt
The following paths are ignored by one of your .gitignore files:
test.txt
Use -f if you really want to add them.
fatal: no files added
$ git add -f test.txt
$ git commit -m "Commit 2"
[master b23a130] Commit 2
1 file changed, 1 insertion(+)
create mode 100644 test.txt
$ echo 'Version 2' > test.txt
$ git add test.txt
$ git commit -m "Commit 3"
[master 60c1f24] Commit 3
1 file changed, 1 insertion(+), 1 deletion(-)
$ cat test.txt
Version 2
$ git checkout b23a130 test.txt
$ cat test.txt
Version 1
如果我在错误的类型提交,我得到这个错误信息:
$ git checkout 6ed8815 test.txt
error: pathspec 'test.txt' did not match any file(s) known to git.
我也得到了错误消息,如果我输入了错误的路径:
$ git checkout b23a130 other.txt
error: pathspec 'other.txt' did not match any file(s) known to git.
您是否尝试从.gitignore中删除该文件? – 2013-03-15 01:11:07
您确定您位于git repostitory下的正确目录中吗?你能确认'git show 234234234b234234234c123424'返回一个有效的输出吗?请注意,您需要将文件的相对位置(从当前位置)或文件的绝对路径提供给'git checkout'命令,并且您需要位于属于git存储库的目录中。 – Tuxdude 2013-03-15 01:21:35
如果该文件被忽略,是不是未跟踪?如果你强制'添加'它,我认为你应该'git重置FILE'来恢复添加。我不知道你是否也想删除文件。 – mgarciaisaia 2013-03-15 01:28:05