日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

git 不小心删除本地文件恢复

發布時間:2024/1/18 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

可見此時沒有任何修改的內容。
再看看具體有什么

xxx@xxx static_files]$ ls abbr_data breakfast_data room_type_data
  • 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中,已經告訴我們怎么辦了。

[xxx@xxx static_files]$ git reset HEAD abbr_data Unstaged changes after reset: M static_files/abbr_data
  • 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 不小心删除本地文件恢复的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。