Is there a way to ask git diff to show the method name instead of the class name?

I don't quite understand why it doesn't work the way it should.

As a temporary solution, add the following to .gitattributes:

*.php   diff=phpf

And these lines to .git/config or ~/.gitconfig:

[diff "phpf"]
        xfuncname = "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$"

For a permanent solution ask Git developers directly at [email protected] mailing list.


If you find yourself having this issue, it might be due to the fact that git lets diff define the hunk header. If you want to force git to use its predefined ones for PHP place the following line in either .gitattributes in the root folder of your git repository or the .git/info/attributes file in your repository:

*.php diff=php

(Other languages are similarly supported. A list of the built in patterns is available in the documentation.)

Setting this Globally

It should be possible to globally set this by doing the following in git version >= 1.4

  1. Put line(s) in ~/.gitattributes
  2. Run git config --global core.attributesfile "~/.gitattributes"

Or if you want to set this globally

  1. Put line(s) into /etc/gitattributes

Warning: If you personally set this globally, your peers may get different results when running git diff since they won't checkout a copy of .gitattributes with the repository.

Tags:

Php

Git

Diff