Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git从bash数组添加多个文件_Git_Bash - Fatal编程技术网

git从bash数组添加多个文件

git从bash数组添加多个文件,git,bash,Git,Bash,我想向git提交添加文件名/路径。我在数组中有文件路径,但当我提交时,我得到: fatal: pathspec 'dist/core.js dist/style.css bower.json Source/core.js' did not match any files 在我之前的脚本中,我有: DIR=`dirname "$0"` for file in "${COREFILES[@]}"; do echo $file="$DIR/$file"; done for file in "${JS

我想向git提交添加文件名/路径。我在数组中有文件路径,但当我提交时,我得到:

fatal: pathspec 'dist/core.js dist/style.css bower.json Source/core.js' did not match any files
在我之前的脚本中,我有:

DIR=`dirname "$0"`
for file in "${COREFILES[@]}"; do echo $file="$DIR/$file"; done
for file in "${JSONFILES[@]}"; do echo $file="$DIR/$file"; done
TARGET_FILES=$(IFS=$' '; echo "${TARGET_FILES[*]}")
TARGET_FILES=( "${COREFILES[@]}" "${JSONFILES[@]}" )
错误行是:

sh -c "cd $DIR && git add '$TARGET_FILES' && git commit -qm 'Current tag $TAG$SUFFIX.'"
脚本中更改文件中源代码的其他部分工作正常。当我执行echo$TARGET\u文件时,我得到一个字符串,空格分隔,看起来都正常

有什么我可能会错过的吗?否则怎么办

git add '$TARGET_FILES'
应该是

git add "${TARGET_FILES[@]}"
这一行没有任何作用,也可能没有帮助:

TARGET_FILES=$(IFS=$' '; echo "${TARGET_FILES[*]}")
另外,我认为您不应该使用
sh-c

cd "$DIR" && git add "${TARGET_FILES[@]}" && git commit -qm "Current tag $TAG$SUFFIX."
整体而言:

DIR=$(dirname "$0")
for file in "${COREFILES[@]}"; do echo "$file=$DIR/$file"; done
for file in "${JSONFILES[@]}"; do echo "$file=$DIR/$file"; done
TARGET_FILES=( "${COREFILES[@]}" "${JSONFILES[@]}" )
cd "$DIR" && git add "${TARGET_FILES[@]}" && git commit -qm "Current tag $TAG$SUFFIX."

很有趣(谢谢你的快速回答!)。因此,
git add“${TARGET_FILES[@]}”是正确的方法,并且像我在这里一样“将数组变成字符串:
TARGET_FILES=$(IFS=$”;echo“${TARGET_FILES[*]}”)
。我理解对了吗?@Rikard
git add
为每个参数添加一个文件,因此必须传递多个参数,而不是一个字符串。是否将命令传递给
ssh
?好的,那么
“${TARGET_FILES[@]}”
被解析为多个参数?所以我用一个字符串做了一个参数。是的,它清晰地扩展到多个参数。甚至元素上的空格也会保留。欢迎使用。很乐意帮忙:)