Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manually run a Git pre-commit hook, without attempting a commit?

Tags:

githooks

I just want to be able to run it to see if the code in my working tree passes it, without actually attempting a commit.

like image 383
callum Avatar asked Jan 17 '18 12:01

callum


People also ask

How do you bypass pre-commit hook?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.

How do you activate pre-commit hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

Can you commit pre-commit hooks?

pre-commit hooks are a mechanism of the version control system git. They let you execute code right before the commit. Confusingly, there is also a Python package called pre-commit which allows you to create and use pre-commit hooks with a way simpler interface.


4 Answers

Just run the pre-commit script through the shell:

bash .git/hooks/pre-commit 
like image 174
Ilayaraja Avatar answered Sep 20 '22 20:09

Ilayaraja


There's a Python package for this available here. Per the usage documentation:

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files. To run individual hooks use pre-commit run <hook_id>.

So pre-commit run --all-files is what the OP is after.

like image 31
javabrett Avatar answered Sep 19 '22 20:09

javabrett


Just run git commit. You don't have to add anything before doing this, hence in the end you get the message no changes added to commit.

like image 35
Yichun Avatar answered Sep 16 '22 20:09

Yichun


For a single file:

pre-commit run --files YOUR_FILENAME
like image 20
Ok Letsdothis Avatar answered Sep 20 '22 20:09

Ok Letsdothis