문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top