golang 编译错误:unknown revision xxx

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."git@gitlab.xxxx.com:".insteadOf http://gitlab.xxxx.com/

通过git配置文件设置:

[url "git@gitlab.xxxx.com:"]
 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/specs-storage@v0.1.1-0.202* 
/root/go-path/pkg/mod/github.com/filecoin-project/specs-storage@v0.1.1-0.20200907031224-ed2e5cd13796:
CONTRIBUTING.md  COPYRIGHT  go.mod  go.sum  LICENSE-APACHE  LICENSE-MIT  Makefile  README.md  storage

/root/go-path/pkg/mod/github.com/filecoin-project/specs-storage@v0.1.1-0.20201105051918-5188d9774506:
CONTRIBUTING.md  COPYRIGHT  go.mod  go.sum  LICENSE-APACHE  LICENSE-MIT  Makefile  README.md  storage

/root/go-path/pkg/mod/github.com/filecoin-project/specs-storage@v0.1.1-0.20211228030229-6d460d25a0c9:
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/specs-storage@v0.1.1-0.20211228030229-6d460d25a0c9=github.com/filecoin-project/specs-storage@v0.1.1-0.20201105051918-5188d9774506
root@jack-VirtualBox:~/lotus/lotus# 

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐墨123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值