git fatal: failed to read object xxx: Invalid argument

后端 未结 2 1046
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 19:50

I am getting the following error if I pull for fetch from remote

$ git pull
remote: Counting objects: 85, done.
remote: Compressing objects: 100% (37/37), do         


        
2条回答
  •  时光说笑
    2020-12-08 20:19

    Finally I was able to fix this issue. I think issue happened when my computer shutdown due to power cut.

    I was able to commit any changes in any of my local branch. This means my pack file is no corrupted but some refs are invalid.

    Back up your .git first. Then I use git fsck command

    $ git fsck --full
    error: inflate: data stream error (unknown compression method)
    error: unable to unpack 38fe6f16c7e8246d61150f0bc42629dbb532b5ce header
    error: inflate: data stream error (unknown compression method)
    fatal: loose object 38fe6f16c7e8246d61150f0bc42629dbb532b5ce (stored in .git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ce) is corrupt
    

    I deleted the file .git/objects/38/fe6f16c7e8246d61150f0bc42629dbb532b5ce and continuing these steps until I get following output:

    $ git fsck --full
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (168543/168543), done.
    error: refs/remotes/origin/staging: invalid sha1 pointer 0000000000000000000000000000000000000000
    error: refs/remotes/origin/development: invalid sha1 pointer 0000000000000000000000000000000000000000
    error: refs/remotes/origin/master: invalid sha1 pointer 0000000000000000000000000000000000000000
    error: bad ref for refs/remotes/origin/staging
    broken link from  commit 8b0fd4094630fea108b60faa15535ffbc85d87cb
                  to  commit bac9f287963b1abb9e4b376b44b4a6500018e9fe
    Checking connectivity: 169821, done.
    dangling blob 750718546640b5b14c19cbdb9958d7bcc4b1114c
    dangling blob e313786318d4c76004728f15a25c6fa68c88b67e
    dangling blob ee3fd85992b48173f6c344a9f4a2f9667d4e1940
    dangling blob cd4898a3ec525e559292337c0bc6b68a77270b52
    dangling blob 9973506f35af1bf4e7790be57b02c70852843f92
    dangling blob 47ca4080b9a528efe23c9f7dce994815f5f9162a
    dangling blob 39d6807d215a7e74fb987d951a90e1d3e24a97eb
    dangling blob c0d650286c3702d56b827eded27eaa9515212847
    dangling commit 53db70d776ec7a59c10db106ef2585abea1ffffffd
    ...
    

    Now I removed all three refs (.git/refs/remotes/origin/master, .git/refs/remotes/origin/staging, .git/refs/remotes/origin/development)

    Voila! Now I was able to pull and push!

    P.S. learned from here

提交回复
热议问题