How can one safely use a shared object database in git?

后端 未结 2 880
心在旅途
心在旅途 2020-12-09 15:48

I have read in several places that it\'s possible to share the objects directory between multiple git repositories, e.g. with symbolic links. I would like to d

相关标签:
2条回答
  • 2020-12-09 16:33

    Perhaps this was added to git after this question was asked/answered: it seems there is now a way to do this explicitly. It's described here:

    https://git.wiki.kernel.org/index.php/Git_FAQ#How_to_share_objects_between_existing_repositories.3F

    How to share objects between existing repositories? Do

    echo "/source/git/project/.git/objects/" > .git/objects/info/alternates
    

    and then follow it up with

    git repack -a -d -l
    

    where the -l means that it will only put ''local'' objects in the pack-file (strictly speaking, it will put any loose objects from the alternate tree too, so you'll have a fully packed archive, but it won't duplicate objects that are already packed in the alternate tree).

    0 讨论(0)
  • 2020-12-09 16:36

    Why not just crank the gc.pruneExpire variable up to never? It's unlikely you'll ever have loose objects 1000 years old that you don't want deleted.

    To make sure that the things which really should be pruned do get pruned, you can keep one repo which has all the others as remotes. git gc would be quite safe in that one, since it really knows what is unreachable.

    Edit: Okay, I was a bit cavalier about the time limit; as is pointed out in the comments, 1000 years isn't gonna work too well, but the beginning of the epoch would, or never.

    0 讨论(0)
提交回复
热议问题