有没有办法运行 git hook before/after 'git add'命令?

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

我检查了 git help hooks,要么不可能,要么我错过了。

我想要这个而不是 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"

并且我想消除手动脚本 运行,因为它毫无意义。

我知道我可以使用 pre-commit 挂钩,但我更喜欢在代码暂存期间编辑工作而不是 reverting/undoing/amending 提交。

很遗憾,我认为这不存在。我认为您最接近的就是创建别名。您不能使用别名覆盖 git 命令,因此您必须使用与 'add'.

不同的名称
git config alias.ad '!./my_script.sh && git add'