2012-10-19 103 views
0
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/ 

我需要從「要提交的更改」返回文件。怎麼做?如何在git repo中意外刪除文件?

+0

你真的讀過你發佈的內容嗎? Git告訴你你需要做什麼:**'(使用「git reset HEAD ...」來取消)'**然後**'(使用「git checkout- ...」來丟棄工作目錄中的變化)**。 – meagar

+0

我知道,但我寫了「git reset HEAD web/img/*」,但它沒有工作,所以我認爲我必須做其他事情。對不起.. – kspacja

+0

如果你已經刪除了'web/img/*',運行'git reset HEAD web/img/*'將不會執行任何操作,因爲shell在調用之前試圖展開'web/img/*' 'git',失敗,因此傳遞字符串'web/img/*','git'會嘗試匹配文本文件名。這是一種痛苦,但是你必須爲每個單獨的文件運行'git reset HEAD web/imgadd-btn-bg.png'等等(或者解析'git status'來生成文件列表(類似' git reset HEAD $(git status | awk'/ deleted:/ {print $ NF}')'(not tested)。 – twalberg

回答

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 

這將unstage刪除操作,然後恢復該文件。

+0

感謝您的回答......但我告訴爲什麼沒有「git reset HEAD web/img/* 「工作對我? – kspacja

+0

沒有工作的原因是因爲」*「是由bash評估的,而不是git。因爲沒有什麼可擴展的(你刪除了這些文件),所以bash只是直接把它傳遞給git。做通配符擴展。 –

相關問題