golang 编译错误:unknown revision xxx

golang 编译错误:unknown revision xxx,第1张

go mod处理第三方依赖包时出现unknown revision xxx错误。

原因:github上面的一些开源组件,用的git版本是最新的版本。 而编辑机的git版本比较旧,有的git命令没有,导致下载失败。

解决方法:升级git到最新版本(目前是2.35.1)。

sudo apt update  # 更新源
sudo apt install software-properties-common # 安装 PPA 需要的依赖
sudo add-apt-repository ppa:git-core/ppa    # 向 PPA 中添加 git 的软件源
sudo apt-get update
sudo apt-get install git

还有原因可能是因为golang包是私有包的问题,配置gomod支持私有包下载:

linux配置
export GOPRIVATE=gitlab.xxx.com/xxxx/*

私有仓库问题:
如果是自己搭建的git 服务器。

golang 设置(私有仓库)环境变量:
go env -w GOPRIVATE="gitlab.xxx.com/xxxx/*"

linux设置环境变量:
export GOPRIVATE=gitlab.xxx.com/xxxx/*

windows设置环境变量:
$env:GOPRIVATE="gitlab.XXXX.com/XXX/*" 

或:

git config --global url."[email protected]:".insteadOf http://gitlab.xxxx.com/

通过git配置文件设置:

[url "[email protected]:"]
 insteadOf = http://gitlab.xxxxx.com/

记住密码:

git config --global credential.helper store

下载依赖:

go mod tidy

或 

go mod download

查看需要替换的依赖包:

root@jack-VirtualBox:~/lotus/lotus# grep -rn "20211228030229-6d460d25a0c9" .
./go.mod:54:	github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9
./go.sum:385:github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9 h1:oUYOvF7EvdXS0Zmk9mNkaB6Bu0l+WXBYPzVodKMiLug=
./go.sum:386:github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9/go.mod h1:Tb88Zq+IBJbvAn3mS89GYj3jdRThBTE/771HCVZdRJU=
./testplans/lotus-soup/go.sum:474:github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9 h1:oUYOvF7EvdXS0Zmk9mNkaB6Bu0l+WXBYPzVodKMiLug=
./testplans/lotus-soup/go.sum:475:github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9/go.mod h1:Tb88Zq+IBJbvAn3mS89GYj3jdRThBTE/771HCVZdRJU=
root@jack-VirtualBox:~/lotus/lotus# 

查看本地现有的包版本:

root@jack-VirtualBox:~/lotus/lotus# ls /root/go-path/pkg/mod/github.com/filecoin-project/[email protected]* 
/root/go-path/pkg/mod/github.com/filecoin-project/[email protected]:
CONTRIBUTING.md  COPYRIGHT  go.mod  go.sum  LICENSE-APACHE  LICENSE-MIT  Makefile  README.md  storage

/root/go-path/pkg/mod/github.com/filecoin-project/[email protected]:
CONTRIBUTING.md  COPYRIGHT  go.mod  go.sum  LICENSE-APACHE  LICENSE-MIT  Makefile  README.md  storage

/root/go-path/pkg/mod/github.com/filecoin-project/[email protected]:
CONTRIBUTING.md  COPYRIGHT  go.mod  go.sum  LICENSE-APACHE  LICENSE-MIT  Makefile  README.md  storage
root@jack-VirtualBox:~/lotus/lotus#

替换依赖包的版本:

root@jack-VirtualBox:~/lotus/lotus# go mod edit -replace=github.com/filecoin-project/[email protected]=github.com/filecoin-project/[email protected]
root@jack-VirtualBox:~/lotus/lotus# 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995805.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存