问题
If you have a pre-commit hook in Git that creates (or modifies) a file, does that file need to be staged for it to be committed?
For example, if I have a pre-commit hook that creates a minified version of some code, do I need to git add
that minified version for it to be included in the commit?
回答1:
Yes, you would have to add the file yourself to the index.
The pre-commit hook allows you to run some commands before committing, that doesn't mean that git will keep track of the modifications made by your hook (or anything external).
That being said, I cannot recommend this kind of practice. Even if it isn't exactly the same thing, it's similar to compile your application and add the result of the compilation to your commit on the fly.
In my opinion, the automatic changes of your code should be done during your build or before your deployment and should have nothing to do with your VCS.
来源:https://stackoverflow.com/questions/14397519/pre-commit-hook-file-staging-for-commit