Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to instruct Visual Studio Code to skip git commit hooks (i.e., to supply the -n argument)?

I would like to be able to install a pre-commit hook, but also to be able to commit under certain circumstances (e.g., WIP) even when the hook fails. I can do this easily from the command line, using git commit --no-verify (git commit -n). But I can't find anything that allows me to affect the commit in VSCode other than the text field for the commit message.

Am I missing it, or is it not there?

like image 893
David P. Caldwell Avatar asked Dec 18 '19 20:12

David P. Caldwell


People also ask

How do I use git commit code in Visual Studio?

Just enter your commit message and then select Commit All. The equivalent command for this action is git commit -a . Visual Studio also makes it easy to commit and sync with one click by using the Commit All and Push and Commit All and Sync shortcuts.

How do you add commit and push in VS Code?

In the text box write in your commit message (if you're wanting to know how to write better commit messages I found this article helpful). Then click the check mark. In Git this is “git commit -m “Updated project links”: Click on the More Options icon, then select “Push”.

How do I set Chrome as my default browser instead of code?

Choose “Open in Default Browser” or “Open in Other Browsers.” If you select the “Open in Default Browser” option, the HTML file will launch in whatever browser is set as default.

Can you debug JavaScript in Visual Studio Code?

The Visual Studio Code editor supports debugging of JavaScript running in Microsoft Edge and Google Chrome. You can read more about debugging browsers works in the Browser Debugging documentation.


2 Answers

Is there a way to instruct Visual Studio Code to skip git commit hooks (i.e., to supply the -n argument)?

Update Sept 2020: there is, with VSCode 1.50 (Sept 2020), which adds the missing option for git commit in VSCode.

See PR 106335: Adds commands for --no-verify commit variants

This PR adds *NoVerify command variants for creating commits while skipping pre-commit and commit-msg hooks.

The commands are only displayed if the git.allowNoVerifyCommit option is set to true.
This type of commits requires additional confirmation (like git.pushForce does), which can be bypassed by disabling the git.confirmNoVerifyCommit option.

See the (now released) VSCode 1.50 "Git: Commit --no-verify commands"

Git commit commands with the --no-verify flag are now available after enabling the git.allowNoVerifyCommit setting.

git --no-verify in command palette -- https://code.visualstudio.com/assets/updates/1_50/git-no-verify.png


Original answer Dec. 2019: From VSCode alone:

  • there is no such option in extensions/git/src/git.ts (but its could be amended by a patch, if a contributor might chose to)

From a VSCode extension, like GitLens

  • there is no such option even in its issues: this has not been requested before.
like image 145
VonC Avatar answered Sep 22 '22 08:09

VonC


Enable No Verify Commits

Go into VSCode settings and enable: git.allowNoVerifyCommit

"git.allowNoVerifyCommit": true

Profit

Source Control Panel

Now you can use the: Commit (No Verify) option through the Source Control panel.

Git commit no verify through source control panel.

Command Palette

Or you can use it through the Command Palette.

Git commit no verify through command palette.

like image 24
CTS_AE Avatar answered Sep 20 '22 08:09

CTS_AE