I can search a string in changes with git log -S "text to find" --stat
. How can I do a similar search, except look for the string in only added or removed lines (not both)?
There is a --diff-filter
option but looks like it filters the whole file rather than individual lines.
2
There is no built-in way to do that.
The closest thing I would see think of be to first run git log -S "text" ...
to identify commits, then scan the diffs:
# get a list of commit hashes from 'git log':
git log --format=%H -S "text" |
# for each commit: do some processing on the diff:
while read sha; do
git diff -U0 -S "text" "$sha"~ "$sha" |
# process ... count number of additions/deletions, and print the
# information you want
done
note that:
git diff
also accepts-S "text"
: this allows to at least narrow the diff to the files involved in contributing to -S-U0
will remove all context lines, if you are interested in counting only the added/removed counts, this may help reduce the number of lines to scan