Skip Git commit hooks

前端 未结 3 1671
长情又很酷
长情又很酷 2020-11-27 08:55

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

相关标签:
3条回答
  • 2020-11-27 09:36

    For those very beginners who has spend few hours for this commit (with comment and no verify) with no further issue

    git commit -m "Some comments" --no-verify
    
    0 讨论(0)
  • 2020-11-27 09:45

    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.

    0 讨论(0)
  • 2020-11-27 09:51

    Maybe (from git commit man page):

    git commit --no-verify
    
    -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.

    0 讨论(0)
提交回复
热议问题