您可以将现有的 git 存储库转换为“blobless”存储库吗?

Nat*_*eed 9 git git-clone

如今,git 提供了“部分克隆”选项,可以下载存储库的提交和树,同时允许按需下载 blob,从而节省网络带宽和磁盘空间。

git clone这可以在初始阶段通过传递 来启用--filter=blob:none。但是,有没有办法将现有的本地存储库转换为“blobless”格式?这应该通过删除已知可从“promisor”远程获取的任何本地 blob 来节省一些磁盘空间。

Cœu*_*œur 2

虽然我不知道专用的就地命令,但您仍然可以执行本地克隆,然后用无 blob 副本替换原始文件夹。
(解决方案灵感来自knittl 评论

# If it's your first time, you'd need to enable filtering locally.
git config --global uploadpack.allowFilter true

# Filter your existing repo into a new one.
# The `file://` protocol followed by a full path is required.
git clone --filter=blob:none file:///full_path_to_existing_repo/.git path_to_new_blobless_copy

# Reconfigure the origin of your new repo.
# You can retrieve it with `git remote -v` in your existing repo.
cd path_to_new_blobless_copy
git remote set-url origin remote_path_to_origin.git
cd -

# Replace your existing repo with the new one.
# Destructive operation that will free up the space of the blobs.
# But will also destroy your local stashes, branches and tags that you didn't clone!
rm -rf /full_path_to_existing_repo
mv path_to_new_blobless_copy /full_path_to_existing_repo
Run Code Online (Sandbox Code Playgroud)