习惯 macOS 后,部分时候使用 Windows 反倒出现各种不适应,本文记录下使用过程中遇到的问题。
报错
在为 Git 配置 GPG 密钥并在 Github 配置 GPG 密钥。
关于配置 Windows 下的 GPG ,请参考 Windows 下 Git 配置 GPG 秘钥
在 Git 中 commit 时使用 GPG 秘钥进行签名
$ git config commit.gpgsign true
查看所有密钥
$ gpg --list-secret-keys --keyid-format LONG
为项目关联秘钥
$ git config --global user.signingkey 0000000000000000000027FDEFF476BB0B000000
上述操作后在 commit 时遇到以下报错
Error
Commit failed - exit code 128 received, with output: 'error: cannot spawn gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to white commit object'
这是因为 Git 程序没有找到 GPG 的可执行文件导致的。
- Windows
git config --global gpg.program 'C:\Program Files (x86)\GnuPG\bin\gpg.exe'
小贴士:后面的可执行文件地址为默认安装位置,若有修改,请自行替换即可。
- macOS
一般情况下不会遇到这种问题,可能是 $PATH 丢失导致的。
git config --global gpg.program $(which gpg)
优化
无法显示中文
找到 Git 配置文件,在安装目录的 \etc
目录下
x64 版本默认安装在 C:\Program Files\Git\etc\bash.bashrc
下
在文件最后添加两行
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
修改后重启终端即可
使用代理
HTTP(S)
终端执行
git config --global http.proxy 'socks5://127.0.0.1:10800'
git config --global https.proxy 'socks5://127.0.0.1:10800'
注意:此种配置只生效于 HTTP 方式拉取或者提交代码,对于 SSH 并不能使用代理。
SSH
为 SSH 方式配置代理
SSH 方式需要使用 connect.exe
进行隧道代理,首先需要明确一点,connect.exe
已经在 Git 安装包中预置了,无需单独下载安装。
Error
Commit failed - exit code 128 received, with output: 'error: cannot spawn gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to white commit object'
这是因为 Git 程序没有找到 GPG 的可执行文件导致的。
- Windows
git config --global gpg.program 'C:\Program Files (x86)\GnuPG\bin\gpg.exe'
小贴士:后面的可执行文件地址为默认安装位置,若有修改,请自行替换即可。
- macOS
一般情况下不会遇到这种问题,可能是 $PATH 丢失导致的。
git config --global gpg.program $(which gpg)
优化
无法显示中文
找到 Git 配置文件,在安装目录的 \etc
目录下
x64 版本默认安装在 C:\Program Files\Git\etc\bash.bashrc
下
在文件最后添加两行
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
修改后重启终端即可
使用代理
HTTP(S)
终端执行
git config --global http.proxy 'socks5://127.0.0.1:10800'
git config --global https.proxy 'socks5://127.0.0.1:10800'
注意:此种配置只生效于 HTTP 方式拉取或者提交代码,对于 SSH 并不能使用代理。
SSH
为 SSH 方式配置代理
SSH 方式需要使用 connect.exe
进行隧道代理,首先需要明确一点,connect.exe
已经在 Git 安装包中预置了,无需单独下载安装。
Error
Commit failed - exit code 128 received, with output: 'error: cannot spawn gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to white commit object'
这是因为 Git 程序没有找到 GPG 的可执行文件导致的。
- Windows
git config --global gpg.program 'C:\Program Files (x86)\GnuPG\bin\gpg.exe'
小贴士:后面的可执行文件地址为默认安装位置,若有修改,请自行替换即可。
- macOS
一般情况下不会遇到这种问题,可能是 $PATH 丢失导致的。
git config --global gpg.program $(which gpg)
优化
无法显示中文
找到 Git 配置文件,在安装目录的 \etc
目录下
x64 版本默认安装在 C:\Program Files\Git\etc\bash.bashrc
下
在文件最后添加两行
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
修改后重启终端即可
使用代理
HTTP(S)
终端执行
git config --global http.proxy 'socks5://127.0.0.1:10800'
git config --global https.proxy 'socks5://127.0.0.1:10800'
注意:此种配置只生效于 HTTP 方式拉取或者提交代码,对于 SSH 并不能使用代理。
SSH
为 SSH 方式配置代理
SSH 方式需要使用 connect.exe
进行隧道代理,首先需要明确一点,connect.exe
已经在 Git 安装包中预置了,无需单独下载安装。
然后修改用户配置文件
vim ~/.ssh/config
加入以下内容
ProxyCommand connect -S 127.0.0.1:10800 -a none %h %p
Host github.com
User git
Port 22
Hostname github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Kane\.ssh\id_rsa"
TCPKeepAlive yes
Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Kane\.ssh\id_rsa"
TCPKeepAlive yes
小贴士:-a none
表示不使用验证方式,-S
指定代理服务器
附录
参考链接
- Git Hub Desktop on Mac, error: cannot run gpg: No such file or directory - stackoverflow
- PhpStorm 配置 Git 并解决 Terminal 中文乱码 - CSDN
- Git 走代理总结(HTTP代理以及SSH设置HTTP代理和Socks代理) - CSDN
- Windows 下 Git SSH 连接方式配置 Socks 代理 - CSDN
本文由 柒 创作,采用 知识共享署名4.0
国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2020-09-21 14:43 PM
日常打卡~ 加油-_-