本文记录一些使用Git Bash for Windows
的小毛病(以及一些技巧)。按照相关软件进行分类
硬盘直接放在根目录下了,所以D:\dev
在git bash中是/d/dev
cd /d/dev
.exe
后缀,影响自动补全参考这个问答 https://superuser.com/a/1119557/1644951
解决办法是在.bashrc
中增加一个开关shopt -s completion_strip_exe
,就像这样:
echo ‘shopt -s completion_strip_exe’ >> ~/.bashrc
然后重启git bash就可以了。
参考 https://learn.microsoft.com/en-us/windows/terminal/dynamic-profiles#git-bash
git for windows在安装时会提供”add profile to windows terminal“,所以重装git也可以解决问题。我选择直接编辑windows terminal的JSON配置项。
docker run --rm -it ubuntu:jammy /bin/bash
不能运行原因:/bin/bash
会被git bash翻译成类似 C:/Program Files/Git/usr/bin/bash
的路径。
解决办法:使用双斜杠开头,避免git bash的翻译。
docker run --rm -it ubuntu:jammy //bin/bash
# 注意这里 -----------------------^
还有一些别的解决办法,请参考这篇文章:https://www.pascallandau.com/blog/setting-up-git-bash-mingw-msys2-on-windows/#the-path-conversion-issue
问题:我从$KUBECONFIG
指向的文件中抽取出了client.pem
,key.pem
,ca.pem
,但是当我使用curl调用k8s的接口时,报错0x80092002
:
admin@REDBOX MINGW64 /d/learning/lfs258/01-curl
$ curl.exe --cert ./client.pem --key ./key.pem --cacert ./ca.pem https://192.168.58.11:6443/api/v1/pods -v
* Trying 192.168.58.11:6443...
* Connected to 192.168.58.11 (192.168.58.11) port 6443
* schannel: disabled automatic use of client certificate
* schannel: Failed to import cert file ./client.pem, last error is 0x80092002
* Closing connection
curl: (58) schannel: Failed to import cert file ./client.pem, last error is 0x80092002
原因:git-bash中的curl使用了windows系统的schannel作为ssl库,但是这个库不支持pem格式的证书。
解决方法:参考 https://stackoverflow.com/q/71325829/11395129
我的解决办法是,去 https://curl.se/windows/ 下载完整版的cURL程序zip包,解压到某个目录,然后在~/.bashrc
中修改PATH变量,使得git-bash优先使用我下载的cURL。
# 我的cURL在这里
/d/tools/curl-8.15.0_4-win64-mingw/bin/curl --version
# curl 8.15.0 (x86_64-w64-mingw32) libcurl/8.15.0 LibreSSL/4.1.0 zlib/1.3.1.zlib-ng brotli/1.1.0 zstd/1.5.7 WinIDN libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.66.0 ngtcp2/1.14.0 nghttp3/1.11.0
# Release-Date: 2025-07-16
# Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
# Features: alt-svc AsynchDNS brotli CAcert HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL SSLS-EXPORT SSPI threadsafe UnixSockets zstd
cat << EOF >> ~/.bashrc
# use my curl
export PATH="/d/tools/curl-8.15.0_4-win64-mingw/bin:$PATH"
EOF
然后重启git-bash,再执行命令就可以了