3 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 首先輸入 git fsck --lost-found
會(huì)看到 一條一條的記錄 類似 dangling commit 7010e0447be96627fde29961d420d887533d7796
復(fù)制dangling commit 的id(其他的dangling blob不用理會(huì)) 然后輸入 git show 7010e0447be96627fde29961d420d887533d7796
查看具體內(nèi)容, 找到你想要的記錄 記錄中會(huì)描述日期和摘要, 日期是你git stash 的日期, 摘要會(huì)記錄你是在哪一條commit 上進(jìn)行g(shù)it stash操作的, 類似(WIP on integration-xf: 2e205ac Merge branch 'release' into develop) 貌似只能一條記錄一條記錄的查看
找到你想要的記錄后輸入 git merge 7010e0447be96627fde29961d420d887533d7796
這樣就還原了你git stash drop, git stash clear 的內(nèi)容 |

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
打開git庫文件,可以看到文件夾內(nèi)的所有文件都沒了,只有一個(gè)git倉庫還存在。
這時(shí)在文件夾上右擊,在彈出的菜單中選擇"Git Bash Here"這一項(xiàng)。
進(jìn)入Bash頁面后,我們執(zhí)行l(wèi)s操作,可以發(fā)現(xiàn),文件夾下同樣不存在文件。
這時(shí)我們?cè)賵?zhí)行g(shù)it reflog。reflog它會(huì)記錄所有HEAD的歷史,也就是說當(dāng)你做 reset,checkout等操作的時(shí)候,這些操作會(huì)被記錄在reflog中。
如果我們要找回文件,只需要做如下操作(*表示上一步中出現(xiàn)的log號(hào)):
git reset --hard *
我們?cè)俅螆?zhí)行l(wèi)s操作,可以發(fā)現(xiàn)文件已經(jīng)還原回來了.
所以,如果因?yàn)閞eset等操作丟失一個(gè)提交的時(shí)候,你總是可以把它找回來。

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
首先git status一把,看看此時(shí)工作區(qū)的狀態(tài)
[xxx@xxx static_files]$ git status
# On branch master
nothing to commit (working directory clean)123
可見此時(shí)沒有任何修改的內(nèi)容。
再看看具體有什么
xxx@xxx static_files]$ ls
abbr_data breakfast_data room_type_data12
此時(shí)總計(jì)有三個(gè)文件。OK,讓我們干掉其中一個(gè)
[xxx@xxx static_files]$ git rm abbr_data
rm 'static_files/abbr_data'
[xxx@xxx static_files]$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: abbr_data
#
[xxx@xxx static_files]$ ls
breakfast_data room_type_data1234567891011
此時(shí)工作區(qū)的文件就只剩兩個(gè)了,abbr_data這個(gè)文件,已經(jīng)被我們干掉。
如果我們想要恢復(fù),怎么辦呢?
[xxx@xxx static_files]$ git checkout -- abbr_data
error: pathspec 'static_files/abbr_data' did not match any file(s) known to git.12
直接checkout,是不行的。
那怎么辦呢?其實(shí)在git status中,已經(jīng)告訴我們?cè)趺崔k了。
[xxx@xxx static_files]$ git reset HEAD abbr_data
Unstaged changes after reset:
M static_files/abbr_data123
用reset命令,先將abbr_data這個(gè)文件找回來。
[xxx@xxx static_files]$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: abbr_data
#
no changes added to commit (use "git add" and/or "git commit -a")123456789
再checkout一把
[xxx@xxx static_files]$ git checkout -- abbr_data
[xxx@xxx static_files]$12
看到checkout以后沒有任何提示,這事就成了。因?yàn)間it的哲學(xué)跟unix的哲學(xué)一樣,沒消息就是最好的消息。。。
再ls一下,果然,abbr_data找回來了。
[xxx@xxx static_files]$ ls
abbr_data breakfast_data room_type_data
- 3 回答
- 0 關(guān)注
- 2015 瀏覽
添加回答
舉報(bào)