git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git fetch --prune fails with "fatal: bad object"

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2024, 15:53 UTC
Message-ID
<xmqqo78kbqwo.fsf@gitster.g>
In-Reply-To
<000501dab3b3$51779400$f466bc00$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
Show 10 quoted lines
>> - Why did the repository got into this state in the first place?
>>   It seems that it would be much better solution to prevent refs
>>   from having garbage values in them or to prevent objects that are
>>   necessary from going away than any "prune invalid refs" feature.
>
> I agree. However, there are some configurations where disk write
> caches are enabled and require a sync or some other flush
> operation to force a complete write to disk. In such situations,
> corruptions are always possible despite the best efforts by the
> application.

The question was posed to see where the current "best efforts" are still inadequate.

Show 9 quoted lines
>> - "fetch" still feels a wrong place to have the feature, if it is
>>   about fixing a local repository corruption.  You should be able
>>   to recover from such a broken ref even if you are only working
>>   locally without fetching from anybody.
>
> I think fsck would be a better place for this.
>
>>If you can somehow _enumerate_ such broken refs, you could drive update-ref to
>>remove them.

Interesting. "git fsck" certainly can be used to help you find out about them. In a throw-away repository, after manually crafting some "broken refs" (because update-ref will refuse to create a ref pointing at a missing object):

    $ git for-each-ref
    9e830ad6c4f43159cef50cb1c2205f513c79bc8b commit refs/heads/master
    $ echo 9e830ad6c4f43159cef50cb1c2205f513c79bc8a >.git/refs/heads/broken-missing
    $ git rev-parse master: >.git/refs/heads/broken-tree
    $ git rev-parse "master:foo /baz" >.git/refs/heads/broken-blob
running "git fsck" does tell you about them, ...
    $ git fsck
    Checking object directories: 100% (256/256), done.
    error: refs/heads/broken-blob: not a commit
    error: refs/heads/broken-missing: invalid sha1 pointer 9e830ad6c4f43159cef50cb1c2205f513c79bc8a
    error: refs/heads/broken-tree: not a commit
... and using the information, you can
    $ for r in refs/heads/broken-{blob,missing,tree}
      do git update-ref -d "$r"
      done
to unbreak the repository.
Previous: rsbecker@nexbridge.comNext: Jeff King
Message 4 of 16 in “git fetch --prune fails with "fatal: bad object"”
  1. Curley JoeMay 31, 2024
  2. Junio C HamanoMay 31, 2024
  3. rsbecker@nexbridge.comMay 31, 2024
  4. Junio C HamanoJun 1, 2024
  5. Jeff KingJun 4, 2024
  6. Junio C HamanoJun 4, 2024
  7. Jeff KingJun 5, 2024
  8. Fred LongJun 4, 2024
  9. Jeff KingJun 5, 2024
  10. Fred LongJun 5, 2024
  11. Jeff KingJun 6, 2024
  12. Fred LongJun 6, 2024
  13. Jeff KingJun 8, 2024
  14. Fred LongJun 8, 2024
  15. Jeff KingJun 11, 2024
  16. Fred LongJun 13, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.