【发布时间】:2019-01-24 17:14:34
【问题描述】:
尝试将 git - add/commit/push 合并到一个功能中。
gitacp testfile/testfile.py "testing" 工作正常。
gitacp testfile/testfile.py "testing this" 会导致这个错误。 错误:pathspec 'this' 与 git 已知的任何文件都不匹配。
由于某种原因,第二个参数中的字符串集不是 得到正确处理。
# Git add, commit and push
function gitacp {
args=("$@")
filepathname=${args[0]}
comment=${args[1]}
branchname=$(git status 2>/dev/null | head -n1 | cut -d" " -f3)
git add ${filepathname}
git commit -m ${comment}
echo ${branchname}
echo ${branchnmrmspc}
echo ${comment}
echo ${filepathname}
git push --set-upstream origin ${branchname}
}
gitacp testfile/testfile.py "testing this" results in this error.
error: pathspec 'this' did not match any file(s) known to git.
【问题讨论】:
-
问题是缺少引号。使用Shellcheck 来识别此类问题以及许多其他问题。