Questions tagged [pre-commit-hook]

In the context of Software Configuration Management (SCM), a pre-commit hook is a command run just before a commit is performed.

Typically, this hook is used to protect against commits that are disallowed due to content or location (e.g. to forbid empty commit log messages).

Usually, i.e. with SVN, if the pre-commit hook program returns a nonzero exit value, the commit is aborted, the commit transaction is removed, and anything printed to stderr is marshalled back to the client.

Related tags

  • Tag may be used in combination with this tag for git specific pre-commit hooks
  • Tag may be used in combination with this tag for SVN specific pre-commit hooks
626 questions
133
votes
29 answers

lint-staged not running on precommit

prettier is not running on precommit. This worked with the same configuration in other projects, so I'm baffled why it's not working this time. This is the relevant section of my package.json file: "scripts": { "precommit": "lint-staged" …
Andrew Horn
  • 2,291
  • 2
  • 16
  • 26
96
votes
10 answers

Can a Git hook automatically add files to the commit?

I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit. How would I go about this? I've tried this as a pre-commit hook, but no…
Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
94
votes
6 answers

Git pre-commit hook : changed/added files

I am writing a pre-commit hook. I want to run php -l against all files with .php extension. However I am stuck. I need to obtain a list of new/changed files that are staged. deleted files should be excluded. I have tried using git diff and git…
igorw
  • 27,759
  • 5
  • 78
  • 90
78
votes
8 answers

husky > pre-commit hook failed (add --no-verify to bypass)

Suddenly I am getting the "husky > pre-commit hook failed (add --no-verify to bypass)" error message when I give the git commit. (C:\Windows\System32\cmd.exe) > git commit husky > npm run -s precommit (node v12.18.3) 'pretty-quick' is not…
Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
75
votes
14 answers

pre-commit/hook: No such file or directory

I get this error when I try to commit. OS - Latest OSX Git version - git version 2.11.0 (Apple Git-81) .git/hooks/pre-commit: line 2: ./node_modules/pre-commit/hook: No such file or directory
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
40
votes
2 answers

Can I use a scripted commit template for git?

We are working on tickets, and when we use the ticket number in the git commit message on the first line, then the ticket is updated with the commit message. To make things simple we always work on a branch with the commit number. Now I'd like to be…
Peter Tillemans
  • 34,983
  • 11
  • 83
  • 114
38
votes
2 answers

Enforce commit message format in git

How can I just enforce a commit message format in Git? Can this be set at a repository level so that everyone who creates a branch will have this enforcement?
Venu
  • 1,513
  • 3
  • 19
  • 37
36
votes
2 answers

Git submodule commit hooks

I'm using a git submodule (let's call it SubmoduleRepo) so that I can include my module in couple of projects. I can commit to SubmoduleRepo from any project that uses it. I can update, commit and push to SubmoduleRepo pretty hassle-free. I need…
Mladen
  • 1,215
  • 1
  • 10
  • 20
35
votes
4 answers

setup pre-commit hook jshint

I recently started a project on github. I've managed to setup automatic testing after each commit using Travis. But now I would like to setup a pre-commit hook with jshint too. So if jshint reports errors, the commit should fail. But is this…
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
34
votes
2 answers

Where does pre-commit install "environments"?

I'm trying to setup pre-commit for a Python project's repository. Upon running pre-commit install I see an output like this: [INFO] Installing environment for https://github.com/asottile/seed-isort-config. [INFO] Once installed this environment will…
planetp
  • 14,248
  • 20
  • 86
  • 160
33
votes
3 answers

Are there any good workarounds to the GitHub 100MB file size limit for text files?

I have a 190 MB plain text file that I want to track on github. The text file is a pronounciation lexicon file for our text-to-speech engine. We regularly add and modify lines in the text files, and the diffs are fairly small, so it's perfect for…
josteinaj
  • 477
  • 1
  • 4
  • 11
32
votes
1 answer

How to run custom shell script file before pre commit hook

In my python project, I have pre-commit-config.YAML where I want to create my custom file. The intention of this file is fail git commit if python lint errors are greater than certain numbers. The following command will be used to count lines pylint…
Kedar Shinde
  • 379
  • 1
  • 4
  • 5
29
votes
2 answers

How to propagate Git Hooks while cloning

I've written a pre-commit hook in my central repository. When my clients clone the repository it never propagates the hooks. I would like the hooks to also be copied to my clients' repositories. My clients are Windows users, using msysgit as the git…
baluchen
  • 749
  • 3
  • 11
  • 18
27
votes
4 answers

How can I use husky to check a git commit message format?

I'm trying to enforce a git commit message policy to keep my repositories clean and tidy. I've seen the official docs about server-side and client-side hooks and then I bumped on husky. So far I could work with the first but couldn't set up husky,…
remmargorp
  • 434
  • 1
  • 6
  • 14
25
votes
4 answers

How do I create a SVN Commit Message Template and Hook to Verify

I'm using Visual SVN Server and Tortoise SVN (client) for source control. I would like all developers to standardize on a consistent format for checkin notes. For Example I want their Commit Message to default to... Synopsis: Developer Name:…
Justin
  • 10,667
  • 15
  • 58
  • 79
1
2 3
41 42