Pre-commit hook file staging for commit

ぃ、小莉子 提交于 2019-12-04 06:08:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!