Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip Git commit hooks

I'm looking at a git hook which looks for print statements in Python code. If a print statement is found, it prevents the git commit.

I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts?

like image 872
Ben Avatar asked Aug 29 '11 13:08

Ben


People also ask

How do you skip commit hooks?

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. Copied! You can also use the -n option, which is short for --no-verify .

How do I disable my husky?

You can set HUSKY environment variable to 0 in your CI config file, to disable hooks installation. Alternatively, most Continuous Integration Servers set a CI environment variable. You can use it in your hooks to detect if it's running in a CI.

How do I skip a prepare commit message?

commit-msg [...] can be bypassed with the --no-verify option. [...] It can also be used to refuse the commit after inspecting the message file.


2 Answers

Maybe (from git commit man page):

git commit --no-verify -m "commit message"            ^^^^^^^^^^^ -n   --no-verify 

This option bypasses the pre-commit and commit-msg hooks. See also githooks(5).

As commented by Blaise, -n can have a different role for certain commands.
For instance, git push -n is actually a dry-run push.
Only git push --no-verify would skip the hook.


Note: Git 2.14.x/2.15 improves the --no-verify behavior:

See commit 680ee55 (14 Aug 2017) by Kevin Willford (``).
(Merged by Junio C Hamano -- gitster -- in commit c3e034f, 23 Aug 2017)

commit: skip discarding the index if there is no pre-commit hook

"git commit" used to discard the index and re-read from the filesystem just in case the pre-commit hook has updated it in the middle; this has been optimized out when we know we do not run the pre-commit hook.


Davi Lima points out in the comments the git cherry-pick does not support --no-verify.
So if a cherry-pick triggers a pre-commit hook, you might, as in this blog post, have to comment/disable somehow that hook in order for your git cherry-pick to proceed.

The same process would be necessary in case of a git rebase --continue, after a merge conflict resolution.

like image 155
VonC Avatar answered Oct 05 '22 12:10

VonC


From man githooks:

pre-commit
This hook is invoked by git commit, and can be bypassed with --no-verify option. It takes no parameter, and is invoked before obtaining the proposed commit log message and making a commit. Exiting with non-zero status from this script causes the git commit to abort.

like image 38
Chris Eberle Avatar answered Oct 05 '22 13:10

Chris Eberle