【问题标题】:Git diff from script来自脚本的 Git 差异
【发布时间】: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 上运行!

标签: git git-diff


【解决方案1】:

一个脚本,它接受一个提交日志消息的正则表达式然后 显示所有提交的 git diff

这不是这样吗?

git log --patch --grep=<pattern>

explainshell.com - git log --patch --grep

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多