由于 sourcetree 上的 husky 预推导致 Git 推送失败

标签 git react-native atlassian-sourcetree git-husky

在推送 React Native 项目时,由于 husky 预推送失败而出现错误

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

显示的所有这些错误都是 lint 错误,如下所示

unused-vars

27:48  error    Trailing spaces not allowed    
                     no-trailing-spaces

75:5   warning  Unexpected console statement   
                     no-console

92:93  error    Unexpected trailing comma   
                        comma-dangle

96:81  error    Unexpected trailing comma

如何在 mac 上的 Sourcetree 应用程序上关闭此功能?

最佳答案

问题(即使它不是真正的问题!)是因为 Husky 创建的钩子(Hook)。 Husky 是一个 npm 包,可让您定义与本地 Git 事件(如提交或推送)相关的 npm 脚本。这有助于在项目中实现协作标准。如果您太忙,快速的解决方案是简单地删除 git 的 hooks 文件夹,它定义了预提交 Hook ,因此可以在之后推送。 (这只是一种避免因 lint 错误而一次编辑数千个文件的 hack。遵循指南并解决所有 lint 错误以获得更好的代码质量和可维护性。) 但最好了解 Husky 和钩子(Hook)的工作原理并正确遵循 lint 警告。

编辑:当您提供 git 命令行参数 —no-verify 时,您也可以跳过钩子(Hook), git push origin master --no-verify,或者使用 Sourcetree 的 Bypass commit hooks 设置(在提交消息字段右上角的菜单中)

关于由于 sourcetree 上的 husky 预推导致 Git 推送失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52754063/

相关文章:

master rebase 后 Git 分支看不到变化

android - React native :Unable to resolve module Indeed, 这些文件都不存在:

Git 取证 : all changes on dev branch disappeared after merge into master

git - 标签可以在 git filter-branch 和 rebase 之后自动移动吗?

git - Powershell 在 TortoiseGit Hook 中不返回任何内容

git - 如何在 github for mac 中取消提交?

android - 在 React Native 中使用 Firebase 显示计时器警告

node.js - 如何在react-native应用程序中实现NTLM身份验证?

git - Sourcetree 的自定义操作保存在哪里?

git - SourceTree - rebase - merge 期间的错误