I use astyle to get my Java and C++ into a unified look. Sometimes I write something and check it into git before running astyle. So I will end up with a commit message like Run astyle which makes cherry-picking and all the like more difficult.

I tried to write a pre-commit hook, but that cannot alter what is going to be commited, it will just fix it in the next commit. I tried a filter, but that does not change the files on the disk.

Is there some neat way to get git to run something before even assessing the changed, other than writing a small script (and remember to use it)?

2 Answers 2


It sounds like if you use both the filter (to fix the committed files) and the pre-commit hook (to fix the files on disk), it will do what you're looking for.


Although this question is rather old, I'm missing one answer:

you can git add [options] within the pre-commit hook, as such the solution is quite simple: just add each file changed by what ever formatter you're using and continue with the commit.

  • 2
    Ellipses tell us your thought it incomplete and leads me to distrust your answer. Please edit your answer to clarify it and make it more specific and concrete. Mar 21, 2022 at 3:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.