Skip to content

Instantly share code, notes, and snippets.

@Lockyy
Last active June 6, 2023 16:20
Show Gist options
  • Save Lockyy/d35c82c489c165ee5fae50ca83c5b2ff to your computer and use it in GitHub Desktop.
Save Lockyy/d35c82c489c165ee5fae50ca83c5b2ff to your computer and use it in GitHub Desktop.
Git blame addition or removal of string in file
git log -S <string> path/to/file
@Lockyy
Copy link
Author

Lockyy commented Feb 28, 2020

https://stackoverflow.com/a/4404551

If you know the contents of the line, this is an ideal use case for:

git log -S <string> path/to/file

which shows you commits which introduce or remove an instance of that string. There's also the -G which does the same thing with regular expressions! See man git-log and search for the -G and -S options, or pickaxe (the friendly name for these features) for more information.

The -S option is actually mentioned in the header of the git-blame manpage too, in the description section, where it gives an example using git log -S....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment