On Wed, Aug 10, 2011 at 10:01:38PM -0700, LovelyLich wrote:
> Hi all....
> I have git clone 
> git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git,
> So, I get an repo for linux  kernel source code .
> What I  want to do is to search for a function changes from version A
> to version B.
> for instance, I want to get change log for function
> "kmem_cache_create"  in file  mm/slab.c  from kernel 2.6.18  to
> 3.0.....
> What I should issue an command?
> I have tried
>            git  log --grep='kmem_cache_create' mm/slab.c
> but this will get many commits and every commit is specified with an
> sha1,  not kernel version  which  i wanted.

What if you did something like this?

        $ git log \
        --grep='kmem_cache_create --pretty=format:%H \
        -- mm/slab.c |
        while read sha1; do
                echo $sha1
                git describe "$sha1"

Be advised that that only finds commits that mention
'kmem_cache_create' in the commit message (--grep).

You might get farther using git blame on the file
and see the commits that make up that function.

Also, the git describe output is a "fuzzy" representation
of the version.

What are you trying to find?  There's a lot you can do once you
have the $sha1.  For example, "git tag --contains $sha1"
would tell you which releases contain the change.

That might be closer to what you're interested in.
If you're interested in commits that touch the function
definition you could try the -S switch, which will show you
everytime content changes containing that string:

        $ git log -S'kmem_cache_create' ...

There's no way to do a general "log for changes to a function"
but git has all the information necessary to implement such
a script.  That'd be a pretty useful script.  I wonder if
anyone's ever written such a thing.

git-blame is the closest to that.  It can be told to look
at the history of a range of lines in a file:


I hope that helps,

git-cola: The highly caffeinated git GUI


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to