栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

golang 编译错误:unknown revision xxx

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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# 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/908893.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号