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

[Bug] data loss with cyclic alternates

From
Ephrim Khong <dr.khong@gmail.com>
Date
Jul 11, 2014, 09:37 UTC
Message-ID
<53BFB055.206@gmail.com>
Hi,

git seems to have issues with alternates when cycles are present (repo A has B/objects as alternates, B has A/objects as alternates). In such cases, gc and repack might delete objects that are present in only one of the alternates, leading to data loss.

I understand that this is no big use case, and requires manual editing of objects/info/alternates. But for the sake of preventing unneccesary data loss, and since I found no warning regarding alternate cycles in the documentation, it might make sense to handle such cases properly (maybe it's a simple "after finding all alternates directories, remove duplicates"?).

Here is a small test case that adds the object storage of a repository as alternate to itsself. After git repack -adl, all objects are deleted.

--- rm -rf test_repo && mkdir test_repo && cd test_repo && git init && touch a && git add a && git commit -m "c1" && git repack -adl && echo $PWD/.git/objects > .git/objects/info/alternates && echo ">> re-packing..." && git repack -adl && echo ">> git fsck..." && git fsck ---

Output:
---
Initialized empty Git repository in /somewhere/test_repo/.git/
[master (root-commit) ab9e123] c1
  1 file changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 a
Counting objects: 3, done.
Writing objects: 100% (3/3), done.
Total 3 (delta 0), reused 0 (delta 0)
 >> re-packing...
Nothing new to pack.
error: refs/heads/master does not point to a valid object!
 >> git fsck...
Checking object directories: 100% (256/256), done.
Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer 1494ec24356cbbbd66e19f22cef762dd83de7f54
error: refs/heads/master does not point to a valid object!
notice: No default references
missing blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
---
Thanks
- Eph
Next: Junio C Hamano
Message 1 of 16 in “[Bug] data loss with cyclic alternates”
  1. Ephrim KhongJul 11, 2014
  2. Junio C HamanoJul 11, 2014
  3. Keller, Jacob EJul 11, 2014
  4. Jeff KingJul 12, 2014
  5. Keller, Jacob EJul 14, 2014
  6. Ephrim KhongJul 13, 2014
  7. sha1_file: do not add own object directory as alternateEphrim Khong, Jul 14, 2014
  8. Duy NguyenJul 14, 2014
  9. Ephrim KhongJul 14, 2014
  10. Johannes SixtJul 15, 2014
  11. sha1_file: do not add own object directory as alternateEphrim Khong, Jul 15, 2014
  12. Junio C HamanoJul 15, 2014
  13. Ephrim KhongJul 16, 2014
  14. Eric SunshineJul 15, 2014
  15. Junio C HamanoJul 15, 2014
  16. Ephrim KhongJul 16, 2014

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.