Posted almost 4 years ago. Visible to the public. Repeats.

Git: Show commits that have touched specific text in a file

If you want to find the commits that touched a specific text in a file, use git log -S 'text in the code' -- path/to/file.


Here is an example, where the move of the convert_number_column_value(value) method in active record is traced (simplified output):

Copy
git log -n 1 --pretty=oneline -S 'convert_number_column_value(value)' -- activerecord/lib/active_record/base.rb ceb33f84933639d3b61aac62e5e71fd087ab65ed Split out most of the AR::Base code into separate modules :cake:
Copy
git show ceb33f84933639d3b61aac62e5e71fd087ab65ed activerecord/lib/active_record/base.rb - def convert_number_column_value(value) - if value == false - 0 - elsif value == true - 1 - elsif value.is_a?(String) && value.blank? - nil - else - value - end - end activerecord/lib/active_record/attribute_methods/write.rb + def convert_number_column_value(value) + if value == false + 0 + elsif value == true + 1 + elsif value.is_a?(String) && value.blank? + nil + else + value + end + end
Copy
git log -n 1 --pretty=oneline -S 'convert_number_column_value(value)' -- activerecord/lib/active_record/attribute_methods/write.rb 5dec3dd59c9f4b5c881860b0f629c8d6b3706f90 delegate attribute typecasting to the column
Copy
git show 5dec3dd59c9f4b5c881860b0f629c8d6b3706f90 activerecord/lib/active_record/attribute_methods/write.rb - def convert_number_column_value(value) - if value == false - 0 - elsif value == true - 1 - elsif value.is_a?(String) && value.blank? - nil - else - value - end activerecord/lib/active_record/connection_adapters/column.rb + def type_cast_for_write(value) + return value unless number? + + if value == false + 0 + elsif value == true + 1 + elsif value.is_a?(String) && value.blank? + nil + else + value + end + end

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Emanuel De
Last edit:
almost 4 years ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more