预提交钩子文件暂存以进行提交 [英] Pre-commit hook file staging for commit

查看:68
本文介绍了预提交钩子文件暂存以进行提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在Git中有一个预提交钩子来创建(或修改)文件,是否需要暂存该文件才能提交?

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?

例如,如果我有一个预提交钩子来创建某些代码的缩小版本,我是否需要git add该缩小版本才能将其包含在提交中?

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?

推荐答案

是的,您必须将文件自己添加到索引中.
pre-commit挂钩允许您在提交之前运行一些命令,这并不意味着git会跟踪您的挂钩(或任何外部)所做的修改.

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.

我认为,代码的自动更改应在构建过程中或部署之前完成,而与VCS无关.

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.

这篇关于预提交钩子文件暂存以进行提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆