Question

I want to know what are the best practices in setting up your pre-commit hooks. What the other developers using Git include in their pre-commit scripts.

In my case, assuming I'm working on a PHP project and having OCD tendencies sometimes - my pre-commit hook includes:

  • PHP syntax checker - commit will fail if there are syntax errors in the committed PHP files.
  • pngout - if the committed file is a png image. pngout will automatically optimize/compress that file.
  • JavaScript syntax checker (in my to-do list)
Was it helpful?

Solution

The usual policy to check for git pre-commit hook is about:

  • comment message (formatting, reference to a work item of sorts)
  • number of files (too many means the commit isn't a coherent "unit", but one large set of files)
  • presence of specific files (like in this hook)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top