Git 与脚本不同
Git diff from script
我正在尝试编写一个脚本,该脚本采用提交日志消息的正则表达式,然后显示所有提交的 git 差异。我的脚本中有以下内容:
#!/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>
我得到以下输出:
command: git diff 806e5e76c0b20eabda3a14b1442168149ad30155
fatal: ambiguous argument '806e5e76c0b20eabda3a14b1442168149ad30155': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'
然而,当我 运行 输出实际命令时,一切正常。有什么想法吗?
a script which takes a regular expression for commit log messages then
displays the git diff across all the commits
这不就可以了吗?
git log --patch --grep=<pattern>
我正在尝试编写一个脚本,该脚本采用提交日志消息的正则表达式,然后显示所有提交的 git 差异。我的脚本中有以下内容:
#!/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>
我得到以下输出:
command: git diff 806e5e76c0b20eabda3a14b1442168149ad30155
fatal: ambiguous argument '806e5e76c0b20eabda3a14b1442168149ad30155': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'
然而,当我 运行 输出实际命令时,一切正常。有什么想法吗?
a script which takes a regular expression for commit log messages then displays the git diff across all the commits
这不就可以了吗?
git log --patch --grep=<pattern>