Posted almost 5 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

Copy
git log -S 'text in the code' -- path/to/file

If you use tig you may run a similar command to get a navigatable list of affected files:

Copy
tig -S'text in the code'

Example

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

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Emanuel De
Last edit:
about 1 month ago
by Henning Koch
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