查找仅更改空格的提交

时间:2015-07-13 20:34:41

标签: git

如何在git分支中找到只有修改空格的更改的所有提交?我不关心合并提交。

更一般地说,根据diff的各个方面找到git提交的最佳方法是什么。我知道git log -S,但这只适用于非常简单的情况(当你想在差异中找到文本时)。

2 个答案:

答案 0 :(得分:2)

这样的事情应该做

branch=<branch you wish to check>
for commit in $(git rev-list --no-merges $branch); do
    if [ -z "$(git diff -b $commit^..$commit)" ]; then
        echo "$commit only modifies whitespace."
    fi
done

答案 1 :(得分:0)

git log -G<regex> can be used to search for commits whose diffs contain lines that match a regular expression.

Note that this is different than saying git log -S<regex> --pickaxe-regex since that will only show commits whose diffs change the number of occurrences of the matching string. In other words, the matching string must appear in either added or removed lines in a given file, but not both.

In your case, you could do something like:

git log -G"^\s+$" --no-merges

where ^\s+$ matches any line in the diff that is nothing but whitespace.

The downside is that this will also include commits whose diffs contain other lines besides the ones with only whitespace.