简体   繁体   English

在检测到修改后的文件后,是否立即运行git钩子?

[英]Is there a git hook that runs immediately after detecting a modified file?

Let's say after git pull - ing -or- git clone - ing , Juan edited a single file called hello-world.txt . 混帐拉后说- 荷兰国际集团 -或者git的克隆 - 荷兰国际集团 ,胡安编辑称为单文件hello-world.txt

Is there a git hook that runs immediately after the modification of the said file? 修改所述文件后是否立即运行git钩子?

I don't think it's possible because there is no hook for file update. 我认为这是不可能的,因为没有挂钩来进行文件更新。

Here's the complete list of hooks available. 这是可用钩子的完整列表。

applypatch-msg
pre-applypatch
post-applypatch
pre-commit
prepare-commit-msg
commit-msg
post-commit
pre-rebase
post-checkout
post-merge
pre-receive
update
post-receive
post-update
pre-auto-gc
post-rewrite
pre-push

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks https://git-scm.com/book/zh/v2/Customizing-Git-Git-Hooks

Hope it helps! 希望能帮助到你!

Git does not have a hook for that, but there are many other tools you can use to watch for changes to files and then run a command. Git并没有为此而钩子,但是您可以使用许多其他工具来监视文件的更改,然后运行命令。 They do require you to start the tool before you make the modification, though. 但是,它们确实要求您在进行修改之前启动工具。

Some tools are listed in the answers to How to execute a command whenever a file changes? 文件更改后如何执行命令的答案中列出了一些工具 . Here are two examples: 这是两个示例:

Running make automatically with entr : 使用entr自动运行make

echo hello-world.txt | entr make

Running make automatically with watchexec : 使用watchexec自动运行make

watchexec --exts txt make

If you don't want to have to start the watching tool yourself, you could try starting it in a Git hook such as post-receive . 如果您不想自己启动监视工具,则可以尝试在Git钩子(例如post-receive启动它。

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

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