[英]How to Commit For Each File Recursively with Git in Bash?
I am trying to push a lot of big binary files to GitHub and it always fails because of big commit sizes. 我正在尝试将许多大的二进制文件推送到GitHub,但由于提交大小较大,它总是会失败。
So I decided to write a bash script which adds and commits each file recursively under given directory, so I can push them one by one. 因此,我决定编写一个bash脚本,该脚本以递归方式在给定目录下添加和提交每个文件,因此可以将它们逐个推送。
This is what I have tried: 这是我尝试过的:
#!/bin/sh
for FILE in ${PROJECT_DIR}/*
do
echo ${FILE}
git add ${FILE}
git commit -m "initial commit ${FILE}"
done
But when file names have spaces or unicode characters, it fails. 但是,当文件名包含空格或Unicode字符时,它将失败。
I am looking for a robust script for this purpose. 我正在为此目的寻找一个健壮的脚本。
The problem is with lack of appropriate quotes in your git add
command. 问题在于您的
git add
命令中缺少适当的引号。 Not enclosing it within double-quotes leaves the variable susceptible to Word-Splitting by the shell ie splitting of a string into individual words by the delimiter (default being the whitespace) 如果不将其括在双引号中,则该变量易于被Shell拆分,即通过定界符将字符串拆分为单个单词(默认为空格)
shopt -s globstar
for fileToCommit in ${PROJECT_DIR}/**/*; do
test -f "$fileToCommit" || continue
printf "%s\n" "${fileToCommit}"
git add "${fileToCommit}"
git commit -m "initial commit ${fileToCommit}"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.