我签出了git lfs存储库。所有二进制文件都是指针。我用git lfs pull --include some/binaries
拉出了真正的二进制文件。
我使用了二进制文件,现在我想“取消”二进制文件并将它们再次转换为指针,这样我就可以回收磁盘空间了。
我没有找到任何合适的命令来执行此操作,并且使用.git / lfs / objects进行修改以及硬重置会让我感到紧张。
问题:如何将跟踪的二进制文件转换回指针?
编辑:
答案 0 :(得分:0)
正如您所提到的,它尚未在git LFS中实现。 Git LFS用户正在使用脚本来实现相同的功能。这是从您的链接中提取的作品。
#!/bin/bash
lfs_files=($(git lfs ls-files -n))
for file in "${lfs_files[@]}"; do
git cat-file -e "HEAD:${file}" && git cat-file -p "HEAD:${file}" > "$file"
done
rm -rf .git/lfs/objects
它只是创建一个由git lfs ls-files返回的所有文件的列表,并遍历该列表,以其指针替换该文件。最后一行从本地存储库中删除所有git LFS对象。
答案 1 :(得分:0)
它将文件转换回指针。
就像撤消git lfs pull
一样。
:-)
#!/bin/bash
# ref: https://github.com/git-lfs/git-lfs/issues/1189#issuecomment-348013275
# ref: https://sabicalija.github.io/git-lfs-intro/
if [ $# -eq 0 ]; then
echo "No input: quit."
exit 1
fi
cur_size=$(du -sh . | awk -F " " '{print $1}')
for bfile in $@; do
# to pointer
# print file size
f_size=$(du -sh $bfile | awk -F " " '{print $1}')
mv $bfile $bfile.bak
cat $bfile.bak | git lfs clean > $bfile
rm $bfile.bak
pt_size=$(du -h $bfile | awk -F " " '{print $1}')
printf "%-30s: " $bfile
printf "%s" $f_size
printf " -> %s \n" $pt_size
# delete cache in .git
hash_value=$(cat $bfile | grep oid | cut -d ":" -f 2)
cache_path=$(find . | grep $hash_value)
if [ -z ${cache_path} ];then
printf "#WARNING# oid can't find in cache: %s \n" $hash_value
else
rm $cache_path
printf ">> Pruned cache at: %s \n" $cache_path
git checkout -- $bfile
fi
done
# report result
after_size=$(du -sh . | awk -F " " '{print $1}')
printf "Finish: Current directory size shrink"
printf "(%s" $cur_size
printf " -> %s).\n" $after_size
exit 0