ILD

Git: Show commits that have touched specific text in a file
作者:Emanuel De 邮箱:NA
发布时间:2019-4-15 站点:Inside Linux Development

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):

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:
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


https://makandracards.com/makandra/42705-git-show-commits-that-have-touched-specific-text-in-a-file



https://git-scm.com/docs/git-log


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.