Trace Git History of a Particular Line
Sometimes you would like to see the full history of a line of code, however git-blame only shows the last commit that touched a line. Using the Rails repository as an example, say you want to see the commits (with the diff included) that touch the #create
method defined in ActiveRecord::Persistence
. You can use the following command:
git log -p -G'def create' activerecord/lib/active_record/persistence.rb
The key is the -G
flag which takes a regular expression. The -p
flag will generate the patch for each commit.
Written by Greggory Rothmeier
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#