我正在尝试将 git 存储库转换为 lfs。我目前正在尝试这个 bash 脚本,并注意到它非常慢。有谁知道如何加快速度?我在整个狂欢中并不真实。
git filter-branch --prune-empty --tree-filter '
git lfs track "*.psd"
git lfs track "*.jpg"
git lfs track "*.png"
git add .gitattributes
git ls-files -z | xargs -0 git check-attr filter | grep "filter: lfs" | sed -E "s/(.*): filter: lfs/1/" | tr "n" " " | while read -r -d $'"' '"' file; do
echo "Processing ${file}"
git rm -f --cached "${file}"
echo "Adding $file lfs style"
git add "${file}"
done
' --tag-name-filter cat -- --all
考虑替换
while read -r -d $'"' '"' file; do
echo "Processing ${file}"
git rm -f --cached "${file}"
echo "Adding $file lfs style"
git add "${file}"
done
跟。。。
xargs -0 sh -c '
printf "Processing file: %sn" "$@"
git rm -f --cached "$@" && git add "$@"
' _
这样,您就不必为每个文件调用一次git rm
和git add
,而是只为每组文件调用一次这两个工具,最大大小不超过环境变量和命令行长度之间共享的可用空间。
我还建议将git lfs track
命令合并为一个调用。例如,如果将源读取到 track
命令,您将看到它支持以下用法:
git lfs track "*.psd" "*.jpg" "*.png"