如何在git repo中意外删除文件?

时间:2012-10-19 15:08:00

标签: git

 On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    web/img/add-btn-bg.png
#       deleted:    web/img/add-tribute-button.png
#       deleted:    web/img/bottom-shadow.png
#       deleted:    web/img/database-line.png
#       deleted:    web/img/glyphicons-halflings-white.png
#       deleted:    web/img/glyphicons-halflings.png
#       deleted:    web/img/header-logo.png
#       deleted:    web/img/horizontal-line.png
#       deleted:    web/img/icons-btn.png
#       deleted:    web/img/icons.png
#       deleted:    web/img/line-bottom-menu.png
#       deleted:    web/img/never-forget.png
#       deleted:    web/img/tribute-icon-line.png
#       deleted:    web/img/uszatek.jpg
#       deleted:    web/img/uszatek_106.jpg
#       deleted:    web/img/uszatek_148.jpg
#       deleted:    web/img/uszatek_32.jpg
#       deleted:    web/img/uszatek_50.jpg
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   web/app_dev.php
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       img/
#       randomNames.csv
#       sampledb.tgz
#       watch/
#       web/assets/
#       web/uploads/

我需要从“要提交的更改”中获取备份文件。怎么做?

1 个答案:

答案 0 :(得分:1)

如果您尚未提交,请按以下方式获取文件(以web/img/glyphicons-halflings-white.png为例):

git reset HEAD web/img/glyphicons-halflings-white.png
git checkout -f web/img/glyphicons-halflings-white.png

这将取消暂存删除操作,然后恢复文件。