問題描述:
公司gitlab更換了git地址,本地統(tǒng)以替換引用git路徑后提交代碼,準(zhǔn)備更新到服務(wù)器上。
本地windows環(huán)境開發(fā)沒有任何問題,再部署測試環(huán)境時(shí)go mod更新包依賴環(huán)境報(bào)錯:
go: xxxxx.cn/infra-components/sdk/microservice-framework/go-framework-plugins.git@v0.1.5: git fetch -f https://xxxxxx.cn/infra-components/sdk/microservice-framework/go-framework-plugins refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/58988a8c52a11bcf34f438ff330fcee1edf52ba472cd02662ad24668e2d34569: exit status 128:
error: RPC failed; result=22, HTTP code = 404
fatal: The remote end hung up unexpectedly
步驟1:
google搜索錯誤原因,得到答案,git地址有問題,缺少.git后綴。
執(zhí)行命令:
git fetch https://xxxxxx.cn/infra-components/sdk/microservice-framework/go-framework-plugins.git
可以正常獲取
執(zhí)行命令:
git fetch -f https://xxxxxx.cn/infra-components/sdk/microservice-framework/go-framework-plugins
得到上述錯誤,驗(yàn)證問題缺失.git后綴
問題:
為何在window上go mod沒有問題了?
在window上執(zhí)行命令
git fetch -f https://xxxxxx.cn/infra-components/sdk/microservice-framework/go-framework-plugins
正常
在其他linux機(jī)器上執(zhí)行該命令同樣正常
步驟2:
為何缺失.git后綴,會出現(xiàn)404的問題。
搜索答案:git會在pull倉庫地址時(shí),會首先嘗試連接不帶.git后綴的倉庫地址,然后在嘗試連接帶.git后綴的地址。兩個(gè)地址都不行的情況下才會判斷出錯。
思考:是否是git版本的問題。
驗(yàn)證:git版本-window機(jī)器:v2.21.0 ;正常go mod的linux機(jī)器:v2.8.4;錯誤go mod的linux機(jī)器:v1.8.3.1
嘗試:升級git版本,git升級到v2.9.5。問題解決。