简体   繁体   English

git pull后恢复文件

[英]Recover file after git pull

Pulling without any local commits deletes staged files without warning. 没有任何本地提交的拉动将删除暂存的文件而不会发出警告。 How can one recover those files? 如何恢复这些文件?

Here is an example showing the issue: 这是显示问题的示例:

~/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

You can recover the contents of the lost files with git fsck --lost-found . 您可以使用git fsck --lost-found恢复丢失文件的内容。

This issue has been reported but I don't believe that the patch has been applied. 已经报告了此问题,但我不认为已应用该补丁。 Posting a follow-up on the git mailing list may help. 在git邮件列表上发布后续邮件可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM