【发布时间】:2015-07-24 16:58:55
【问题描述】:
我正在尝试编写一个脚本,该脚本采用提交日志消息的正则表达式,然后显示所有提交的 git diff。我的脚本中有以下内容:
#!/bin/sh
ARGV=("$@")
dir=$(pwd)
commits=($(git --work-tree ${dir} log --grep ${ARGV[0]} | grep -o 'commit .*$' | cut -f2 -d' '))
echo $(git --work-tree ${dir} log --grep ${ARGV[0]})
for i in ${commits[@]}
do
echo "command: git diff ${i}"
echo $(git diff ${i})
done
当我运行 /path/to/script.sh <some-regex> 时,我得到以下输出:
命令:git diff 806e5e76c0b20eabda3a14b1442168149ad30155
致命:不明确的参数“806e5e76c0b20eabda3a14b1442168149ad30155”:未知修订版或路径不在工作树中。 使用 '--' 将路径与修订分开,如下所示: 'git [...] -- [...]'
但是,当我运行输出的实际命令时,一切正常。有什么想法吗?
【问题讨论】:
-
你在哪个shell中执行这个脚本?它甚至不能在 bash 上运行!