2

I cannot succeed fixing a git broken link.

Here is the context :

$ git pull
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
warning: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

error: inflate: data stream error (unknown compression method)
error: unable to unpack 9a684a736e3b97ff7c709138259196fd223e661c header
fatal: loose object 9a684a736e3b97ff7c709138259196fd223e661c (stored in .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c) is corrupt
fatal: failed to run repack

Already up to date.
$ git fsck
error: inflate: data stream error (unknown compression method)
error: unable to unpack header of .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c
error: 9a684a736e3b97ff7c709138259196fd223e661c: object corrupt or missing: .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c
Checking object directories: 100% (256/256), done.
Checking objects: 100% (5766/5766), done.
Checking connectivity: 12924, done.
dangling tree bd85f5cb37f9545d81b7f923978f97c4eaf391ea
dangling tree 978c24540576bfa8d0e748a33e2457c6286a0d64
dangling blob 0d91b9e2423b61d3f941a3571f08459e3f7db21f
dangling blob 4c4112f5aaa60d99ef2c8a4bb66e855eb1bac7e6
missing tree 9a684a736e3b97ff7c709138259196fd223e661c
$ git cat-file -t 9a684a736e3b97ff7c709138259196fd223e661c
error: inflate: data stream error (unknown compression method)
error: unable to unpack 9a684a736e3b97ff7c709138259196fd223e661c header
fatal: git cat-file: could not get object info
$ du .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c
0   .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c

So I removed this empty file according to this :

$ rm .git/objects/9a/684a736e3b97ff7c709138259196fd223e661c
rm: remove write-protected regular file '.git/objects/9a/684a736e3b97ff7c709138259196fd223e661c'? y
$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (5766/5766), done.
broken link from  commit fca8efc10a91c7ac2cd0acf5d6744c1cb1ea9765
              to    tree 9a684a736e3b97ff7c709138259196fd223e661c
Checking connectivity: 12924, done.
dangling tree bd85f5cb37f9545d81b7f923978f97c4eaf391ea
dangling tree 978c24540576bfa8d0e748a33e2457c6286a0d64
dangling blob 0d91b9e2423b61d3f941a3571f08459e3f7db21f
dangling blob 4c4112f5aaa60d99ef2c8a4bb66e855eb1bac7e6
missing tree 9a684a736e3b97ff7c709138259196fd223e661c

So I tried the solutions described here :

$ git gc --aggressive
fatal: bad tree object 9a684a736e3b97ff7c709138259196fd223e661c
fatal: failed to run repack
$ git stash clear
$ git reflog expire --expire-unreachable=now --all
$ git gc --prune=now
fatal: bad tree object 9a684a736e3b97ff7c709138259196fd223e661c
fatal: failed to run repack
$ git fsck --name-objects
Checking object directories: 100% (256/256), done.
Checking objects: 100% (5766/5766), done.
broken link from  commit fca8efc10a91c7ac2cd0acf5d6744c1cb1ea9765 (~11)
              to    tree 9a684a736e3b97ff7c709138259196fd223e661c (~11:)
Checking connectivity: 12924, done.
dangling tree bd85f5cb37f9545d81b7f923978f97c4eaf391ea
dangling tree 978c24540576bfa8d0e748a33e2457c6286a0d64
dangling blob 0d91b9e2423b61d3f941a3571f08459e3f7db21f
dangling blob 4c4112f5aaa60d99ef2c8a4bb66e855eb1bac7e6
missing tree 9a684a736e3b97ff7c709138259196fd223e661c (~11:)
$
SebMa
  • 4,037
  • 29
  • 39
  • This is a *damaged repository*. There are no Git tools for *fixing* one; in general, most people just throw them away and re-clone. If that's not suitable for some reason, you can find help for doing certain hand-fixes, but "bad tree object" is a difficult one. – torek Oct 20 '21 at 21:55

1 Answers1

1

Beside trying to fix a corrupted repository, make sure to use Git 2.37 (Q3 2022)

See commit 7c89855, commit 4627c67, commit 29d8e21, commit 58407e0 (12 May 2022) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit 1b8138f, 23 May 2022)

object-file: fix a unpack_loose_header() regression in 3b6a8db3b03

Signed-off-by: Ævar Arnfjörð Bjarmason

Fix a regression in my 3b6a8db (object-file.c: use , 2021-10-01, Git v2.34.0-rc0 -- merge listed in batch #15) (object-file.c: use "enum" return type for unpack_loose_header(), 2021-10-01) revealed both by running the test suite with --valgrind, and with the amended "git fsck"(man) test.

In practice this regression in v2.34.0 caused us to claim that we couldn't parse the header, as opposed to not being able to unpack it.

Before the change in the C code the test_cmp added here would emit:

-error: unable to unpack header of ./objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
+error: unable to parse header of ./objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391

I.e.
we'd proceed to call parse_loose_header() on the uninitialized "hdr" value, and it would have been very unlikely for that uninitialized memory to be a valid git object.

The other callers of unpack_loose_header() were already checking the enum values exhaustively.
See 3b6a8db and 5848fb1 (object-file.c: return ULHR_TOO_LONG on , 2021-10-01, Git v2.34.0-rc0 -- merge listed in batch #15) (object-file.c: return ULHR_TOO_LONG on "header too long", 2021-10-01).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for answer. Do you know of a Launchpad PPA to install an up to date git release ? – SebMa May 24 '22 at 06:45
  • 1
    @SebMa Try [what I described here](https://stackoverflow.com/a/41357503/6309) for Git ppa upgrade. But 2.37 isn't released yet. – VonC May 24 '22 at 06:57