Git grep across all new and modified files (before commit)
问题 What command can I run in my Windows Git Bash that will show me the file names, line preview (context), and line numbers of all of the places there is "TODO" written in my code, limited to new files and modified files? Inadequate Approach 1 (from here) This is clunky and doesn't print line number: function __greptodo { QUERY="TODO" for FILE in `git diff --name-only`; do grep "$QUERY" $FILE 2>&1 >/dev/null if [ $? -eq 0 ]; then echo '———————————————' echo $FILE 'contains' $QUERY grep "$QUERY"