Git list commits that contain a string with diff around the changed line containing that string

Viewed 141

Let's say I have a function called MySuperFunction. How do I list all commits that added/removed/changed/used this function, with the context of that change only?

For example, if commit c added a line using this function and 100 other lines, I want to see: The commit hash, the commit message, the commit's author and date (optional), and most importantly: a diff around the line where the function was added - with 5 lines before and after for context (with file name and line numbers), but not the entire 100 lines of the commit.

What I tried and why didn't it work:

  • git log -p | grep -C5 "MySuperFunction" - does print the diffs with context, but no commit information.
  • git grep "MySuperFunction" - only prints the current uses of MySuperFunction
  • git log -GMySuperFunction - only prints the commit information, but no diff
  • git log -GMySuperFunction -p - prints commit info and diff, but it prints the entire diff of each commit, not just the lines around MySuperFunction
  • git rev-list --all | GIT_PAGER=cat xargs git grep 'MySuperFunction' - prints all commints that contain "MySuperFunction" in their content, not their diff

Is there any git log option for this, or do I have to write my own script that will take the output of git log -GMySuperFunction -p and filter through the diff only, leaving the commit information?

0 Answers
Related