2012-06-19 192 views
2

沒有任何本地提交時拉起沒有警告的刪除分步文件。如何恢復這些文件?git pull後恢復文件

下面是該問題的一個例子:

~/git $ git --version 
git version 1.7.5.4 

~/git $ uname -a 
Darwin Joe-MacMini.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 

~/git $ mkdir TESTDIR 
~/git $ cd TESTDIR/ 

~/git/TESTDIR $ echo "hi" > file.txt 

~/git/TESTDIR $ git init 
Initialized empty Git repository in /Users/joe/workspace/git/TESTDIR/.git/ 

~/git/TESTDIR (master #%) $ git add file.txt 

~/git/TESTDIR (master #) $ git status 
# On branch master 
# 
# Initial commit 
# 
# Changes to be committed: 
# (use "git rm --cached <file>..." to unstage) 
# 
# new file: file.txt 
# 

~/git/TESTDIR (master #) $ ls -al 
total 8 
drwxr-xr-x 4 joe staff 136 Jun 19 14:52 . 
drwxr-xr-x 19 joe staff 646 Jun 19 14:52 .. 
drwxr-xr-x 11 joe staff 374 Jun 19 14:52 .git 
-rw-r--r-- 1 joe staff 3 Jun 19 14:51 file.txt 

~/git/TESTDIR (master #) $ git remote add origin [email protected]:joecabezas/GitLogGroupByDate.git 

~/git/TESTDIR (master #) $ git reflog 
fatal: bad default revision 'HEAD' 

~/git/TESTDIR (master #) $ git pull origin master 
remote: Counting objects: 3, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From github.com:joecabezas/GitLogGroupByDate 
* branch   master  -> FETCH_HEAD 

~/git/TESTDIR (master) $ ls -al 
total 8 
drwxr-xr-x 4 joe staff 136 Jun 19 14:53 . 
drwxr-xr-x 19 joe staff 646 Jun 19 14:52 .. 
drwxr-xr-x 13 joe staff 442 Jun 19 14:53 .git 
-rw-r--r-- 1 joe staff 148 Jun 19 14:53 README.md 

~/git/TESTDIR (master) $ git reflog 
8583332 [email protected]{0}: initial pull 
+0

你可以升級到最新的Git版本,看看這是否仍然是一個問題?您的版本是最新版本(v1.7.11)的一種方式。 –

回答

1

可以恢復丟失的文件的內容與git fsck --lost-found

此問題has been reported但我不相信該補丁已被應用。在git郵件列表上發佈後續信息可能會有所幫助。