您必須指定錯誤的提交或錯誤的路徑。
$ 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