Git 工具內建更新功能,執行 git update-git-for-windows 指令即可自動下載更新。(參考:更新本機 Git 到最新版 by Poy)

不過在受管控網路環境,簡單到靠北的下載動作也會因 SSL 憑證問題卡關,我已見怪不怪:

不意外地,git update-git-for-windows 果然也因為 SSL 憑證問題失敗。

λ git update-git-for-windows
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

由訊息判斷,git.exe 背後是靠 curl 查詢及下載最新版,遇到防火牆或防毒軟體偷換 SSL 根憑證,就會因為憑證不被信任而失敗。curl 本身有 --insecure 可忽略 SSL 憑證檢查,但 update-git-for-windows 時沒這選項,所幸在 Stackoverflow 查到一篇討論,提到在 Git\mingw64\bin\ 目錄下新增 curl-ca-bundle.crt 檔案加入要信任的根憑證,可以解決問題。借用 IE 的設定介面找到要信任的根憑證,按匯出:

格式記得選 Base64:

匯出結果為文字檔,內容類似這樣:

-----BEGIN CERTIFICATE-----
MIIC7DCCAdSgAwIBAgIQEgSCt0oUtKtNgxV+CzckJzANBgkqhkiG9w0BAQUFADAU
MRIwEAYDVQQDEwlKZWZmV2luMTAwIBcNMTgwODE4MDQ1MzQ2WhgPMzAxNzEyMTkw
...省略...
xOV7v+AtwgLSxsTc0mGfbQmMTxLYBInI6Nv1fyei8IRTv8bYHlTFgeFR/2NEMn2n
1K8AlLIC1W1aegEGt5Tv9oY2O3Gsj3B3XywDB7Lo3ro=
-----END CERTIFICATE-----

將檔名更名為 curl-ca-bundle.crt 複製到 Git\mingw64\bin\ 目錄(Cmder 的 Git 則在 cmder\vendor\git-for-windows\ming64\bin),就能成功更新了。

λ git update-git-for-windows
Git for Windows 2.29.1.windows.1 (64bit)
Update 2.33.1.windows.1 is available
Download and install Git for Windows 2.33.1 [N/y]? y
###################################################################### 100.0%
###################################################################### 100.0%

又學到奇怪技能,分享給有緣人。


Comments

Be the first to post a comment

Post a comment