加速 bash 脚本将 git repo 转换为 LFS

Speed up bash script converting git repo to LFS

我正在尝试将 git 存储库转换为 lfs。我现在正在试用这个 bash 脚本,发现它非常慢。有谁知道如何加快速度?我对这整个 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//" | tr "\n" "[=12=]" | while read -r -d $'"'[=12=]'"' 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 $'"'[=10=]'"' 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: %s\n" "$@"
  git rm -f --cached "$@" && git add "$@"
' _

这样,您不必为每个文件调用一次 git rmgit add,您只需为每组文件调用一次这两个工具,直到达到可用文件中的最大大小space 在您的环境变量和命令行长度之间共享。


我还建议将您的 git lfs track 命令合并到一个调用中。例如,如果您阅读 the source to the track command,,您会看到它支持以下用法:

git lfs track "*.psd" "*.jpg" "*.png"