Disable pre-commit hooks on merge commits
Answered
When I'm on a feature branch and do "merge into current" on master, the pre-commit hooks are run. Can I disable that?
I want to keep the pre-commit hooks on normal commits.
Please sign in to leave a comment.
As I understand you mean the automatic commits done by the merge command? To skip hooks one need to pass --no-verify flag, and it appears that git merge does not support such a flag,
As a workaround, you could configure git to never commit automatically on merge, and conclude merges with manual commits.
When committing from IDE then, disable the Run Git Hooks checkbox, or commit with the --no--verify flag from the command line
Is there some way to have the "Run Git Hooks" checkbox in the commit dialog *not* be checked by default. I have to uncheck it every time. Whenever I neglect to, I get a hard to see error in the bottom right saying the commit failed because it can't find git hook files.
It's pretty annoying.
@Kevin
> *not* be checked by default
No. Why do you have hooks in your project if you don't want to run them? The checkbox is there only when there are active hooks in the project.
> I get a hard to see error in the bottom right saying the commit failed because it can't find git hook files
Seems there is something wrong with the configured hooks, as it is git itself running them, not IDE. Probably you should fix or remove hooks instead of disableing the checkbox.
There's an NPM package called "pre-commit" that I no longer wanted. I neglected to uninstall it. I just removed the dependency entry from the package.json file. It didn't occur to me that it would need to run an uninstall process via `npm uninstall pre-commit`.
It works now as you said.
> No. Why do you have hooks in your project if you don't want to run them?
Because sometimes we work on join projects and don't have permission to remove the hooks. However, during local development it's easier to just disable them on IDE level, than to have to delete pre-commit package everytime a new branch is pulled and then install it back when ready to commit upstream.
Please vote for https://youtrack.jetbrains.com/issue/IDEA-235213
Workaround
.git/hooks/pre-commit
or any other hooks you have..skip-hooks
with a single line containingtrue
orfalse
.Run Git Hooks
in the IntelliJ dialog to checked.Ok so, for me, the problem was that we use the npm package Husky to setup our git hooks in npm, and Husky just installs itself to all of the git hooks even if they are not all declared in our package.json.
According to the git documentation: "The default pre-merge-commit hook, when enabled, runs the pre-commit hook, if the latter is enabled." https://git-scm.com/docs/githooks#_pre_merge_commit
So it seems that simply defining an empty pre-merge-commit command in package.json should prevent the default pre-commit hook from running on merges.
Im working in PHPStorm, but the problem is same. I also want to be able to disable pre-commit in the commit window for node peoject. We're running npm in the docker container and all commands must be done in it. But IDE does not supports remote node interpretation. So as all packages installed via containers npm, husky commands fails in hosts node.
We have a monorepo on my project, which sucks already, but FEs messed up their hooks and my fellow BE devs struggle with merges now. Failed automatic branch merge results in all changesets piling up togethers, which makes them USELESS and adds an hour of headache separating temporary local hacks from useful code.
Every merge is a risk of huge pain now and I move into git terminal more and more because of how bad default IDEA behavior is.
If your features require extra steps from us - they should be disableable.
Fix it please!
@...
Do I understand correctly that the main issue here is that changes got into the same changelist?
Could you please go to Preferences | Version Control | Changelists and check "Create changelists automatically" - it is enabled or disabled?
That's so annoying that I'm going to switch to VS code
We also want this! We have Git hooks which perform code quality analysis checks when we commit. However, whenever we merge develop or master into our ticket branches to catch up with changes, we are not interested in performing any quality checks, as it is not our code!