我有一個 .git/index 檔案,我想恢復一個檔案。如果我使用命令 git status 我會看到:
└─$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: app.py
new file: exploit.py
new file: flag.txt
new file: templates/index.html
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: app.py
deleted: exploit.py
deleted: flag.txt
deleted: templates/index.html
我需要閱讀 flag.txt 檔案的內容。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
根據我對 Git 的理解,您可以使用git restore flag.txt將對其的更改回滾到最近的提交。
uj5u.com熱心網友回復:
我的猜測——這只是一個猜測——是您正在一個 Git 存盤庫中作業,該存盤庫存盤在某種云同步作業區(Google Drive、iCloud 等)中。根據您在此評論中的內容:
[
git restore flag.txt產生錯誤資訊:]error: unable to read sha1 file of flag.txt (c4bef48579d85bb52df9f0bf5a0873dad3d632e3)
你的索引檔案是完整的,但你的 Git 存盤庫本身沒有,已經被其他一些軟體損壞了——可能是說 cloud-syncer,盡管你自己也有可能洗掉了.git目錄的一部分(我們無法判斷,因為你沒有顯示我們您以前的行為)。
不幸的是,這意味著您無法取回您的檔案,或者至少不能從 Git取回。你的git status文字:
└─$ git status On branch master No commits yet
顯示您在一個空的存盤庫中,其中當前的分支名稱 ,master用于不存在的分支。
同時:
Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: app.py new file: exploit.py new file: flag.txt new file: templates/index.html
Git 的索引(也稱為staging area)表明有四個新檔案準備提交。這些檔案具有名稱—— app.py、exploit.py等——以及(未顯示)內部物件哈希 ID。不幸的是,錯誤訊息,你得表明,哈希ID flag.txt,即c4bef48579d85bb52df9f0bf5a0873dad3d632e3,實際上并不存在在Git的資料庫,或已損壞。
同時:
Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: app.py deleted: exploit.py deleted: flag.txt deleted: templates/index.html
這表明這些檔案的作業樹副本也不再存在。
因此,我們可以得出以下結論:
這些不再作為普通檔案存在。如果可能的話,您將不得不使用一些非 Git 檔案恢復軟體將它們恢復為普通檔案。
這些確實曾經作為 Git 內部物件存在,例如
c4bef48579d85bb52df9f0bf5a0873dad3d632e3forflag.txt. 該.git/index檔案仍然完好無損,并且仍然記錄了路徑名flag.txt和內部 Git 物件哈希 ID。但是 Git 內部物件
c4bef48579d85bb52df9f0bf5a0873dad3d632e3丟失了:有些東西將它洗掉了。所以 Git 無法讀取物件來獲取檔案的內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/368842.html
標籤:混帐
