Abel Callejo
Abel Callejo

Reputation: 14969

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.

Is there a git hook that runs immediately after the modification of the said file?

Upvotes: 1

Views: 89

Answers (2)

Rory O'Kane
Rory O'Kane

Reputation: 30428

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. 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:

echo hello-world.txt | entr make

Running make automatically with watchexec:

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.

Upvotes: 1

Nimeshka Srimal
Nimeshka Srimal

Reputation: 8950

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

Hope it helps!

Upvotes: 4

Related Questions