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
May 31, 2024, 23:27 UTC
Message-ID
<xmqqplt1d0k0.fsf@gitster.g>
In-Reply-To
<16919-1717194882-875013@sneakemail.com>
"Curley Joe" <m48cv7wg9w@liamekaens.com> writes:
Show 7 quoted lines
> git fetch --prune fails with "fatal: bad object" for refs that
> have an invalid sha1 pointer. It would be nice if "git fetch
> --prune" could prune these refs, because it is a hassle to do it
> manually. ("git fetch --prune" only shows the first invalid ref,
> and you have to run "git fsck" and parse it to find the rest.) If
> it seems like adding this functionality to --prune is a bad idea,
> then how about adding an option like "--prune-invalid" ?
A question and a comment.
 - 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.
 - "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.

If you can somehow _enumerate_ such broken refs, you could drive update-ref to remove them. Naïvely, an obvious place to add such a feature might be the "for-each-ref" command that is used to list refs with various criteria, so it might look like:

   $ git for-each-ref --format='%(refname)' --broken |
     xargs git update-ref -d
or something?
Previous: Curley JoeNext: rsbecker@nexbridge.com
Message 2 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.