Svn was used in the last project and git was used in the new project. I was very happy and finally learned GIT. I thought I had learned git, but I still encountered a problem that was not within the scope of my knowledge points. Finally, my colleagues helped solve it
Question: when the code commits for the first time, it always reports errors. After reading the error information, it seems that the code errors will be checked before committing, but the code has no errors. Can it run?Will the errors checked by eslint be checked out, and then the commit fails?Finally, I found a solution on the Internet
first, let’s get to know git’s hook:
Hooks are stored in the hooks subdirectory under the GIT directory. That is. Git/hooks in most projects. When initializing a new version library with git init, GIT will place some sample scripts in this directory by default. In addition to being called by themselves, these scripts also reveal the parameters passed in when triggered. All the examples are shell scripts, some of which are mixed with Perl code, but any properly named executable script can be used normally
GIT_DIR/hooks/pre-commit :
This hook is called by the GIT commit command and can be skipped by adding the — no verify parameter to the command. This hook requires no parameters and is called before getting the commit message and starting the commit. If the return value of the hook is not 0, the GIT commit command will abort execution
Note: this hook can be used to check for code errors before submitting (for example, running a lint program)
When the default pre commit hook is enabled, if it finds a blank line at the end of the file, it will abort the submission
Similar Posts:
- Sourcetree / git solves the problem of pre commit hook failed
- Git missing Change-Id in commit message footer [How to Solve]
- VSCode git commit Error: No such file or directory [How to Solve]
- [Solved] Git Error: pre -commit hook failed (add –no-verify to bypass)
- remote: ERROR: [28b83b5] missing Change-Id in commit message footer
- [Solved] Git review Error: Errors running git rebase -i remotes/gerrit/master
- [Solved] Pyinstaller package Error: AttributeError: ‘str’ object has no attribute ‘decode’
- [Solved] Pull is not possible because you have unmerged files
- [Cherry-pick Failed Error merging] You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists). Please, commit your changes before you merge.
- fatal: Not a git repository (or any of the parent directories): .git