GitHub blog covers the highlights from Git 2.19, which was recently released.
One particular change that I want to highlight (which GitHub skipped in their highlights, but which exists in the Git release notes for this version) is the syntax pattern update for the PHP files.
Let’s have a look at the full diff of this release. The particular change I am referring to is in the userdiff.c file.  Git now understands final, abstract, interface, and trait keywords.
If you are not sure where and how it is used, here are a couple of useful links for you:
- .gitattributes documentation section on settings the syntax of the file for diffs. Basically, you just need to add “*.php diff=php” to the .gitattributes file. Unfortunately, this is done on a per-project level, rather than globally on a user level. (See this blog post for more details).
- More info on the same subject: How Does Git Know What Functions Look Like?
Now that you have it all configured, there are a couple of ways to benefit from this functionality. First, you’ll see a more useful context comment in the diffs. Here’s the screenshot (using an older git version still). On the left, the diff without the PHP syntax configured, and on the right is the diff with the PHP syntax configured:
As you can see, on the left, the context shows that the change was done somewhere in the ChangeLogTrait trait. On the right, the context is much more specific – it shows that the change was done in the public function changelog.
This makes reviewing code changes a lot easier. But there is also one other place where this is useful – in reviewing the history of a particular function. For example, running “git log -L :changelog:ChangelogTrait.php” will produce the git log output containing only the commits and diffs on the function changelog in the file ChangelogTrait.php. Very handy!