3 回答
TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
我有一個(gè)類似的問題。我的筆記本電腦在git操作期間電量耗盡。噓。
我沒有任何備份。(注意,Ubuntu One不是git的備份解決方案;它將用損壞的存儲(chǔ)庫有幫助地覆蓋您的健全存儲(chǔ)庫。)
對(duì)于git向?qū)В绻@是修復(fù)它的不好方法,請(qǐng)發(fā)表評(píng)論。但是,它確實(shí)為我工作了……至少是暫時(shí)的。
第1步:備份.git(實(shí)際上,我在更改某些步驟的每一步之間進(jìn)行此操作,但是使用新的復(fù)制到名稱,例如.git-old-1,.git-old-2等) :
cp -a .git .git-old
步驟2:執(zhí)行 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再次運(yùn)行。繼續(xù)刪除空文件。您還可以cd進(jìn)入.git目錄并運(yùn)行find . -type f -empty -delete -print以刪除所有空文件。最終git開始告訴我它實(shí)際上是在處理對(duì)象目錄:
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實(shí)際運(yùn)行:
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。失敗,因?yàn)槲业念^壞了。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reflog
fatal: bad object HEAD
步驟6:Google。找到這個(gè)。手動(dòng)獲取reflog的最后兩行:
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ tail -n 2 .git/logs/refs/heads/master
f2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d Nathan VanHoudnos <nathanvan@gmail.com> 1347306977 -0400 commit: up to p. 24, including correcting spelling of my name
9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f Nathan VanHoudnos <nathanvan@gmail.com> 1347358589 -0400 commit: fixed up to page 28
步驟7:請(qǐng)注意,從步驟6中我們了解到HEAD當(dāng)前指向最后的提交。因此,讓我們嘗試僅查看父提交:
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:所以現(xiàn)在我們需要將HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d
哪個(gè)沒抱怨。
步驟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指針?biāo)坪鮼碜杂冢ìF(xiàn)已過時(shí))索引文件(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
在晃來晃去斑點(diǎn)不是錯(cuò)誤。我不關(guān)心master.u1沖突,現(xiàn)在它可以正常工作了,我不想再碰它了!
第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
因此,希望將來對(duì)人們有用。我很高興它奏效。
TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
git對(duì)象文件已損壞(也如其他答案所指出)。這可能在機(jī)器崩潰等情況下發(fā)生。
我有同樣的事情。在閱讀了其他頂級(jí)答案之后,我發(fā)現(xiàn)了使用以下命令修復(fù)損壞的git存儲(chǔ)庫的最快方法(在包含該.git文件夾的git工作目錄中執(zhí)行):
(確保首先備份您的git倉庫文件夾?。?/p>
find .git/objects/ -type f -empty | xargs rm
git fetch -p
git fsck --full
這將首先刪除所有導(dǎo)致整個(gè)存儲(chǔ)庫損壞的空對(duì)象文件,然后從遠(yuǎn)程存儲(chǔ)庫中獲取丟失的對(duì)象(以及最新更改),然后進(jìn)行完整的對(duì)象存儲(chǔ)檢查。在這一點(diǎn)上,應(yīng)該可以成功執(zhí)行而不會(huì)出現(xiàn)任何錯(cuò)誤(盡管可能還會(huì)有一些警告!)
PS。這個(gè)答案表明您在某個(gè)地方(例如,在GitHub上)有一個(gè)git存儲(chǔ)庫的遠(yuǎn)程副本,而損壞的存儲(chǔ)庫是與仍處于正常狀態(tài)的遠(yuǎn)程存儲(chǔ)庫綁定的本地存儲(chǔ)庫。如果不是這種情況,請(qǐng)不要嘗試按照我的建議進(jìn)行修復(fù)。
TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊
解決了此問題,刪除了git fsck檢測到的各種空文件,然后運(yùn)行簡單的git pull。
我感到失望的是,即使文件系統(tǒng)也實(shí)現(xiàn)了日記功能和其他“事務(wù)性”技術(shù)來保持fs的正常運(yùn)行,由于電源故障或設(shè)備空間不足,git可能會(huì)陷入損壞狀態(tài)(并且無法自行恢復(fù))。
- 3 回答
- 0 關(guān)注
- 2771 瀏覽
添加回答
舉報(bào)
