亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復GIT錯誤:目標文件為空?

如何修復GIT錯誤:目標文件為空?

Git
四季花海 2019-09-27 16:29:10
當我嘗試提交更改時,出現以下錯誤:error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is emptyfatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt任何想法如何解決此錯誤?編輯我試過git fsck了error: object file .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71 is emptyfatal: loose object 03dfd60a4809a3ba7023cbf098eb322d08630b71 (stored in .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71) is corrupt
查看完整描述

3 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

我有一個類似的問題。我的筆記本電腦在git操作期間電量耗盡。噓。


我沒有任何備份。(注意,Ubuntu One不是git的備份解決方案;它將用損壞的存儲庫有幫助地覆蓋您的健全存儲庫。)


對于git向導,如果這是修復它的不好方法,請發表評論。但是,它確實為我工作了……至少是暫時的。


第1步:備份.git(實際上,我在更改某些步驟的每一步之間進行此操作,但是使用新的復制到名稱,例如.git-old-1,.git-old-2等) :


cp -a .git .git-old

步驟2:執行 git fsck --full


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full

error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e is empty

fatal: loose object 8b61d0135d3195966b443f6c73fb68466264c68e (stored in .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e) is corrupt

步驟3:刪除空文件。我想通了。反正還是空白。


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e 

rm: remove write-protected regular empty file `.git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e'? y

步驟3:git fsck再次運行。繼續刪除空文件。您還可以cd進入.git目錄并運行find . -type f -empty -delete -print以刪除所有空文件。最終git開始告訴我它實際上是在處理對象目錄:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full

Checking object directories: 100% (256/256), done.

error: object file .git/objects/e0/cbccee33aea970f4887194047141f79a363636 is empty

fatal: loose object e0cbccee33aea970f4887194047141f79a363636 (stored in .git/objects/e0/cbccee33aea970f4887194047141f79a363636) is corrupt

步驟4:刪除所有空文件后,我最終開始git fsck實際運行:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full

Checking object directories: 100% (256/256), done.

error: HEAD: invalid sha1 pointer af9fc0c5939eee40f6be2ed66381d74ec2be895f

error: refs/heads/master does not point to a valid object!

error: refs/heads/master.u1conflict does not point to a valid object!

error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-tree

dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2

missing blob 8b61d0135d3195966b443f6c73fb68466264c68e

missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4

dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a

missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd

missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

步驟5:嘗試git reflog。失敗,因為我的頭壞了。


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reflog

fatal: bad object HEAD

步驟6:Google。找到這個。手動獲取reflog的最后兩行:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ tail -n 2 .git/logs/refs/heads/master

f2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d Nathan VanHoudnos <[email protected]> 1347306977 -0400  commit: up to p. 24, including correcting spelling of my name

9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f Nathan VanHoudnos <[email protected]> 1347358589 -0400  commit: fixed up to page 28

步驟7:請注意,從步驟6中我們了解到HEAD當前指向最后的提交。因此,讓我們嘗試僅查看父提交:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git show 9f0abf890b113a287e10d56b66dbab66adc1662d

commit 9f0abf890b113a287e10d56b66dbab66adc1662d

Author: Nathan VanHoudnos <nathanvan@XXXXXX>

Date:   Mon Sep 10 15:56:17 2012 -0400


    up to p. 24, including correcting spelling of my name


diff --git a/tex/MCMC-in-IRT.tex b/tex/MCMC-in-IRT.tex

index 86e67a1..b860686 100644

--- a/tex/MCMC-in-IRT.tex

+++ b/tex/MCMC-in-IRT.tex

有效!


步驟8:所以現在我們需要將HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d

哪個沒抱怨。


步驟9:看看fsck怎么說:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full

Checking object directories: 100% (256/256), done.

error: refs/heads/master.u1conflict does not point to a valid object!

error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-tree

dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2

missing blob 8b61d0135d3195966b443f6c73fb68466264c68e

missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4

dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a

missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd

missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

步驟10:高速緩存樹中的無效sha1指針似乎來自于(現已過時)索引文件(source)。所以我殺了它并重置了倉庫。


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/index

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reset

Unstaged changes after reset:

M   tex/MCMC-in-IRT.tex

M   tex/recipe-example/build-example-plots.R

M   tex/recipe-example/build-failure-plots.R

步驟11:再次查看fsck ...


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full

Checking object directories: 100% (256/256), done.

error: refs/heads/master.u1conflict does not point to a valid object!

dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2

dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a

在晃來晃去斑點不是錯誤。我不關心master.u1沖突,現在它可以正常工作了,我不想再碰它了!


第12步:掌握本地編輯信息:


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git status

# On branch master

# 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:   tex/MCMC-in-IRT.tex

#   modified:   tex/recipe-example/build-example-plots.R

#   modified:   tex/recipe-example/build-failure-plots.R

#

< ... snip ... >

no changes added to commit (use "git add" and/or "git commit -a")



nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "recovering from the git fiasco"

[master 7922876] recovering from the git fiasco

 3 files changed, 12 insertions(+), 94 deletions(-)


nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git add tex/sept2012_code/example-code-testing.R

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "adding in the example code"

[master 385c023] adding in the example code

 1 file changed, 331 insertions(+)

 create mode 100644 tex/sept2012_code/example-code-testing.R

因此,希望將來對人們有用。我很高興它奏效。


查看完整回答
反對 回復 2019-09-27
?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

git對象文件已損壞(也如其他答案所指出)。這可能在機器崩潰等情況下發生。


我有同樣的事情。在閱讀了其他頂級答案之后,我發現了使用以下命令修復損壞的git存儲庫的最快方法(在包含該.git文件夾的git工作目錄中執行):


(確保首先備份您的git倉庫文件夾?。?/p>


find .git/objects/ -type f -empty | xargs rm

git fetch -p

git fsck --full

這將首先刪除所有導致整個存儲庫損壞的空對象文件,然后從遠程存儲庫中獲取丟失的對象(以及最新更改),然后進行完整的對象存儲檢查。在這一點上,應該可以成功執行而不會出現任何錯誤(盡管可能還會有一些警告?。?/p>


PS。這個答案表明您在某個地方(例如,在GitHub上)有一個git存儲庫的遠程副本,而損壞的存儲庫是與仍處于正常狀態的遠程存儲庫綁定的本地存儲庫。如果不是這種情況,請不要嘗試按照我的建議進行修復。


查看完整回答
反對 回復 2019-09-27
?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

解決了此問題,刪除了git fsck檢測到的各種空文件,然后運行簡單的git pull。

我感到失望的是,即使文件系統也實現了日記功能和其他“事務性”技術來保持fs的正常運行,由于電源故障或設備空間不足,git可能會陷入損壞狀態(并且無法自行恢復)。


查看完整回答
反對 回復 2019-09-27
  • 3 回答
  • 0 關注
  • 2694 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號