简体   繁体   English

有没有办法在'git add'命令之前/之后运行git hook?

[英]Is there way to run git hook before/after 'git add' command?

I checked git help hooks and either it is impossible or I missed this. 我检查了git help hooks ,或者这是不可能的,或者我错过了。

I want this rather than pre-commit as program in repository generates files, as result my current workflow is 我希望这样做而不是pre-commit因为存储库中的程序会生成文件,因此我当前的工作流程是

git add -A ruby script_stored_in_repository_that_generates_something.rb <checking generated work that is not tracked in the repository> git commit -m "what was changed"

and I want to eliminate manual script run as pointless. 而且我想消除手动脚本运行毫无意义的情况。

I know I can use pre-commit hook, but I prefer to edit work while code is staged rather than reverting/undoing/amending commits. 我知道我可以使用pre-commit钩子,但是我更喜欢在暂存代码时编辑工作,而不是还原/撤消/修改提交。

Unfortunately I don't think that exists. 不幸的是,我认为那不存在。 I think the closest you can come is to make an alias. 我认为最接近的别名是。 You can't override git commands with alias so you must use a different name than 'add'. 您不能使用别名覆盖git命令,因此您必须使用与“ add”不同的名称。

git config alias.ad '!./my_script.sh && git add'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM