git:识别所有不符合模式的提交

时间:2015-06-12 10:00:37

标签: git grep git-rev-list

我正在尝试使用不以[core]开头的消息来识别所有提交。这些是我失败的尝试:

  1. 简单方法

    git rev-list --grep '^(?!(\[core\]).).+' "branch1...branch2"
    
    • 空结果
  2. 启用扩展标记

    git rev-list -E --grep '^(?!(\[core\]).).+' "branch1...branch2"
    
    • 错误消息fatal: command line, '^(?!(\[core\]).).+': Invalid preceding regular expression

    • git grep似乎不支持负面预测。

  3. 将所有提交列表与带有标记(cf. this answer)的列表进行比较:

    git rev-list "branch1...branch2" | grep -Fxv <(git rev-list -E --grep '^\[core\].+' "branch1...branch2")
    
    • sh: syntax error near unexpected token `('
    • 中的结果
  4. P.S:我无法升级到Git 2.x,因此--invert-grep不是选项

2 个答案:

答案 0 :(得分:1)

这样的事情可能有用。

git rev-list "branch1...branch2" --not $(git rev-list --grep '^\[core\]')

选择该列表中与您不想要的模式匹配的修订,然后在--not的另一次调用中使用rev-list否定该修订列表。

您还可以通过使用如下实际文件来避免第三次尝试中的进程替换:

git rev-list -E --grep '^\[core\].+' "branch1...branch2" > core.list
git rev-list "branch1...branch2" | grep -Fxvf core.list

答案 1 :(得分:0)

如果它符合您使用批处理文件的要求,这是一个解决方案:

#!/bin/sh
range="branch1...branch2"
validCommits=`git rev-list -E --grep '^\[core\]' "$range"`
badCommits=`git rev-list "$range" | grep -Fxv "$validCommits"`
相关问题