由于对 sourcetree 的 husky pre-push 导致 Git 推送失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52754063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git push failed due to husky pre-push on sourcetree
提问by krishnakumarcn
While pushing a react native project, I'm getting error due to husky pre-push failed
在推送 React Native 项目时,由于 husky pre-push 失败,我收到错误
husky > pre-push hook failed (add --no-verify to bypass)
husky > pre-push hook failed (add--no-verify to bypass)
All these errors shown are lint errors like the below
显示的所有这些错误都是如下所示的 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
How to turn this off on Sourcetree app on mac?
如何在 Mac 上的 Sourcetree 应用程序上关闭此功能?
采纳答案by krishnakumarcn
Finally found a solution. The issue (even though it's not an issue! ) is because of the hooks created by react. I simply deleted the hooks folder for git which defines the pre-commit hooks and hence can push after that.
终于找到了解决办法。问题(即使它不是问题!)是因为 react 创建的钩子。我只是删除了 git 的 hooks 文件夹,它定义了预提交挂钩,因此可以在此之后推送。
Edit: You can also skip hooks when you provide the git command line argument —no-verify,
git push origin master --no-verify
, or use Sourcetree‘s Bypass commit hooks setting (in the menu to the top right of the commit message field)
编辑:您还可以在提供 git 命令行参数时跳过钩子——no-verify
git push origin master --no-verify
, 或使用 Sourcetree 的绕过提交钩子设置(在提交消息字段右上角的菜单中)
回答by MwamiTovi
I thought it equally important to help you understand the husky
tool.
And I found this articlevery helpful in managing this situation, when I struggled too.
我认为帮助您理解该husky
工具同样重要。
我发现这篇文章对管理这种情况非常有帮助,当我也很挣扎时。
Huskyis an npm package that lets you define npm scripts that correlate to local Git events such as a commit or push. And this helps in enforcing collaborative standards in a project.
Husky是一个 npm 包,可让您定义与本地 Git 事件(例如提交或推送)相关的 npm 脚本。这有助于在项目中执行协作标准。
In your project, you mention that all errors are linked to linting.
So in there, husky
scripts were written to create a git hook
, called pre-push
, which enforces code lintingbefore you can git push
successfully.
在您的项目中,您提到所有错误都与 linting 相关联。
因此,在那里husky
编写了脚本来创建一个git hook
名为 的pre-push
,它会在您成功之前强制执行代码 lintinggit push
。
In my opinion, especially if you are working in a team, DO NOT turn-off/deactivate these checks and DO NOT delete the .git/hooks
folder. Instead go back and run the lint script
(often found in the package.json
), amend the required changes and once you git push
again you'll be successful.
在我看来,尤其是如果您在团队中工作,请不要关闭/停用这些检查,也不要删除.git/hooks
文件夹。而是返回并运行lint script
(通常在 中找到package.json
),修改所需的更改,然后git push
再次成功。
回答by Hamid Mohamadi
Add --no-verify to the end of your push command .
在 push 命令的末尾添加 --no-verify 。
git push origin master --no-verify
回答by Tomachi
Add --no-verify to the end of your commit short term.
将 --no-verify 添加到短期提交的末尾。
I'm also on Mac and started seeing these I think with working on a Carlo app that I instantiated inside my main project folder. I came Googling over to stack overflow due to I wasn't sure what Husky is ('husky' command not installed), so I started digging around to find a linter, guessed to try eslint .
我也在 Mac 上,并开始看到这些,我认为是通过在我的主项目文件夹中实例化的 Carlo 应用程序工作的。由于我不确定 Husky 是什么('husky' 命令未安装),我开始谷歌搜索堆栈溢出,所以我开始四处寻找 linter,猜测尝试 eslint 。
? src_aminosee git:(master) ? eslint .
Error: Cannot find module '@ljharb/eslint-config'
Referenced from: /Users/tom/Dropbox/Sites/funk.co.nz/aminosee/carlojet/node_modules/array-includes/.eslintrc
This is when I realised that I have a git repo inside of a git repo here ('carlojet' try out folder inside 'aminosee' main project)!! I'd have to (should) move that folder out. Not sure if this type of nested repo issue is what was causing your issue, but after moving thusly and attempt a commit I see:
这是当我意识到我在这里的 git 存储库中有一个 git 存储库时('carlojet' 尝试在 'aminosee' 主项目中的文件夹)!!我必须(应该)将该文件夹移出。不确定这种类型的嵌套 repo 问题是否是导致您出现问题的原因,但在如此移动并尝试提交后,我看到:
git commit -am "moved carlojet folder out as i think its git repo conflicted with this main one"
Can't find Husky, skipping pre-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping prepare-commit-msg hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping commit-msg hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
Can't find Husky, skipping post-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
My knowledge of git is lacking, but to me, it's like those files are now waving "good bye" having left the repo; or more likely "winking" at me having up traversed into their parents aminosee/.git/hooks/ directory (that was a surprise!), from their true home in aminosee/carlojet/.git/hooks/
我缺乏对 git 的了解,但对我来说,就像这些文件现在已经离开 repo 挥手“再见”一样;或者更有可能对我“眨眼”,从他们在aminosee/carlojet/.git/hooks/的真正家中遍历到他们的父母aminosee/.git/hooks/目录(这是一个惊喜!)
I may need to disable all these hooks duplicated from other project... or better still bring up that linter! I guess not great idea to nest git repo inside itself in my case.
我可能需要禁用从其他项目中复制的所有这些钩子……或者最好还是调出那个 linter!我想在我的情况下将 git repo 嵌套在内部并不是一个好主意。