git pull之后恢复文件

时间:2012-06-19 18:59:43

标签: git

在没有任何本地提交的情况下进行提取会删除暂存的文件而不会发出警告。如何恢复这些文件?

以下是显示问题的示例:

~/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 git@github.com: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 HEAD@{0}: initial pull

1 个答案:

答案 0 :(得分:1)

您可以使用git fsck --lost-found恢复丢失文件的内容。

此问题has been reported但我不相信该修补程序已应用。在git邮件列表上发布后续内容可能会有所帮助。