Skip to content

Instantly share code, notes, and snippets.

@kstevens715
Last active April 5, 2018 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kstevens715/ece63989a4e75f9a99921ab05fe7473f to your computer and use it in GitHub Desktop.
Save kstevens715/ece63989a4e75f9a99921ab05fe7473f to your computer and use it in GitHub Desktop.
Git command to search history of a file for some text. This helps find when something was removed from a file.
#!/usr/bin/env ruby
# Usage:
# To search for all occurrences in history of text "perform" in app/models/model.rb:
#
# git search-file-history perform app/models/model.rb
#
# TODO: A good future enhancement would be to show the commit right after the last occurrence, to see where it was removed.
#
text, filename = ARGV
puts `git grep #{text} $(git rev-list --all -- #{filename}) -- #{filename}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment