Git 那些事儿:轻松搞定提交、连接与包管理难题

101 阅读2分钟

解决pnpm管理Vue项目时Git Commit失败的404错误

为了节省硬盘空间,使用pnpm作为vue的管理命令行工具,但在使用pnpm作为vue项目的包管理器时,遇到了git commit失败的问题,错误信息显示为404NotFound,涉及npmregistry中的--no-install命令。

报错信息如下:

/root/.local/share/pnpm/store/v3/tmp/dlx-9631:
 ERR_PNPM_FETCH_404  GET https://registry.npmjs.org/--no-install: Not Found - 404

This error happened while installing a direct dependency of /root/.local/share/pnpm/store/v3/tmp/dlx-9631

--no-install is not in the npm registry, or you have no permission to fetch it.

No authorization header was set for the request.

解决方案: 通过安装并更新husky到v8,以及移除v4配置,成功修复了提交问题。

pnpm install husky@8 --save-dev 
pnpx husky-init 
pnpx -- github:typicode/husky-4-to-8 --remove-v4-config

原文链接

解决因Node默认版本问题导致的Git操作失败

好吧,之后发现出现以上情况是因为node版本错误(nvm总是自动切换到最新版本),切换回指定版本就好了。所以这里再讲讲设置nvm默认node版本。以上内容还是保留,说不定有用得上的时候。

nvm list //查看node本地版本
nvm alias default v14.16.0//设置默认版本
nvm current //查看当前node版本

Nvm alias之后需要重启vscode的,不然是不生效的!

解决SSH连接错误:指定ssh-rsa密钥类型

在尝试通过SSH连接到指定的IP地址和端口时,客户端和服务器之间没有匹配的主机密钥类型。服务器提供的是ssh-rsa,但客户端可能默认不再支持这种较旧的主机密钥类型。

报错信息如下:

Unable to negotiate with 192.168.133.58 port 29418: no matching host key type found. Their offer: ssh-rsa
fatal: Could not read from remote repository.

Please make sure you have the correct access rights 
and the repository exists.

解决方案:~/.ssh/config文件中为特定的主机添加配置,指定使用ssh-rsa密钥类型。这将告诉SSH客户端在与主机连接时,除了默认启用的密钥类型外,还接受ssh-rsa密钥类型。

Host * 
HostkeyAlgorithms +ssh-rsa 
PubkeyAcceptedKeyTypes +ssh-rsa

通过编辑~/.ssh/config文件为特定的SSH连接指定HostKeyAlgorithms +ssh-rsa,应该能够解决用户在使用Git Bash拉代码时遇到的错误。但请注意,这只是一个临时且可能不那么安全的解决方案,长期来看应该考虑升级服务器的SSH配置。

更新中……