See the History of a Method with git log -L

Caleb Hearth - Nov 5 '23 - - Dev Community

Git can “trace the evolution” of a specific method when passed -L using the :<funcname> variant. Let’s take a look at the history of this blog’s posts’ published scope, which is used in most places that articles are listed out. You can see that git is able to identify the boundaries of the method even as the length changes and it prints out the full method with diff from each commit in the log, which is filtered to changes to that method.

$ git log -L :self.published:app/models/post.rb -n3
commit d1fbdf3b9a5bd37dd49d61c61ee0f51c75fdb806
Author: Caleb Hearth <caleb@calebhearth.com>
Date:   Thu Feb 2 16:36:34 2023 -0700

    Decree, LFW, new homepage, RSS-only posts

diff --git a/app/models/post.rb b/app/models/post.rb
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -15,6 +15,6 @@
   def self.published
     all
-      .reject { _1.frontmatter[:draft] }
+      .reject { _1.frontmatter[:draft] || _1.tags.include?("rss-only") }
       .select { _1.date <= Date.today }
   end
Enter fullscreen mode Exit fullscreen mode

Read more

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .