git 不小心删除本地文件恢复
生活随笔
收集整理的這篇文章主要介紹了
git 不小心删除本地文件恢复
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
有時候不小心在Git中rm了文件。怎么恢復呢?別急,咱們一步步來。
首先git status一把,看看此時工作區的狀態
[xxx@xxx static_files]$ git status # On branch master nothing to commit (working directory clean)- 1
- 2
- 3
- 1
- 2
- 3
可見此時沒有任何修改的內容。
再看看具體有什么
- 1
- 2
- 1
- 2
此時總計有三個文件。OK,讓我們干掉其中一個
[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_data- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
此時工作區的文件就只剩兩個了,abbr_data這個文件,已經被我們干掉。
如果我們想要恢復,怎么辦呢?
[xxx@xxx static_files]$ git checkout -- abbr_data error: pathspec 'static_files/abbr_data' did not match any file(s) known to git.- 1
- 2
- 1
- 2
直接checkout,是不行的。
那怎么辦呢?其實在git status中,已經告訴我們怎么辦了。
- 1
- 2
- 3
- 1
- 2
- 3
用reset命令,先將abbr_data這個文件找回來。
[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")- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
再checkout一把
[xxx@xxx static_files]$ git checkout -- abbr_data [xxx@xxx static_files]$- 1
- 2
- 1
- 2
看到checkout以后沒有任何提示,這事就成了。因為git的哲學跟unix的哲學一樣,沒消息就是最好的消息。。。
再ls一下,果然,abbr_data找回來了。
[xxx@xxx static_files]$ ls abbr_data breakfast_data room_type_data總結
以上是生活随笔為你收集整理的git 不小心删除本地文件恢复的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【1058】求一元二次方程
- 下一篇: UE风格化Day20-光照函数/关于相机