I'm using this git hook for preventing commits that include non-ascii characters.
When I find a non-ascii character, I want to print only the line with the character (and if possible the filename and line number too)
git --no-pager diff HEAD -S$char -U0
The --unified option will show all changes in the file, but I just want to show the lines -S found.
This is not exactly a
diffformat, but you can easily get what you want by addingxargsandgrepto the mix:With GNU grep, you can replace
grep -n "$char" /dev/nullwithgrep -Hn "$char"