3

I have a project in Git. In my code, at some point in the past, I removed a call to a public function. I would like to know when I removed the call to this function, and why. Because the function call is in a different file than the function definition, I can't simply look at the file history of the file that defines the function. Is there an easy way to look for files that contain calls to a function?

I'll try to illustrate this:

File: MyFuncCall.cs //older version

    public void Foo()
    {
        //do something ...
    }

File: ???.cs //older version

    public void Bar()
    {
        new MyFuncCall().Foo();
        //do something else...
    }

After some commits, the code now looks like:

File: MyFuncCall.cs //newer version

    public void Foo()
    {
        //do something ...
    }

File: ???.cs //newer version

    public void Bar()
    {
        //no more call to function
        //do something else...
    }

In this illustration, I want to know what ???.cs is.

user2023861
  • 8,030
  • 9
  • 57
  • 86

1 Answers1

4

It is called the log "pickaxe" (git log):

git log -Sfunction

The oldest one will be the commit where that function has been introduced in your code.
The next one can be where it has been deleted.

See "How to grep git commits for a certain word": it differs from git log --grep=function, which greps within the commit message.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Cool. It'd be nice if that git command showed not only the commit information, but also the file name containing the search phrase. All I needed to do was a quick text search of the commit. Thanks. – user2023861 Jun 03 '14 at 19:31
  • @user2023861 then `git log -p` can help too (http://stackoverflow.com/a/23128003/6309). Otherwise, regarding `git log -S`, maybe adding `-U0` can help too (http://stackoverflow.com/a/14164826/6309) – VonC Jun 03 '14 at 19:37