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

标签 git bash shell sed git-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/\1/" | tr "\n" "\0" | while read -r -d $'"'\0'"' 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 $'"'\0'"' 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 了,只需为每组文件调用一次这两个工具(最大大小)这将适合环境变量和命令行长度之间共享的可用空间。


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

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

关于git - 加速 bash 脚本将 git repo 转换为 LFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35179945/

相关文章:

macos - mac系统级git配置

linux - Git 困惑。 "fatal: failed to open ' app/lang/en/homepage.php': File exists"

linux - 一个衬垫,用于使用 xargs 在其他命令生成的搜索文本上 grep 一个命令的输出

linux - 捕获标准错误和标准输出的好方法

python - 启动时运行的脚本不记录输出

linux - 如何在 zshell 中以关键字拆分字符串并保存结果?

linux - shell 脚本输出中的语言正在发生变化

git - TortoiseGit 麻烦 : git did not exit cleanly (exit code 128)

java - $JAVA_HOME 变量随每个新终端而变化

git - 作为 git 预提交钩子(Hook)执行 vim 命令