英文:
How to resolve Go module declares its path as "x" but was required as "y" between 2 versions
问题
最近我不得不将私有仓库从SaaS Gitlab迁移到本地版本。一切都进行得很顺利,我做了以下操作:
- 将仓库
a
中旧的go模块路径从old.com/workspace/a
更新为new.com/workspace/a
。 - 在最新的提交上添加了一个新的标签
v1.2.3-new
。 - 将仓库
b
更新为引用最新的标签v1.2.3-new
,路径为new.com/workspace/a
。 - 在仓库
b
中运行go mod tidy
并验证其是否正常工作。
现在我有一个要求,需要引用new.com/workspace/a
的旧版本标签(最初是old.com/workspace/a
)。因此,在仓库a
中,我切换到了旧的标签,并将模块路径从old.com/workspace/a
修复为new.com/workspace/a
,并将其标记为v1.1.1-new
。
然后在仓库b
中,我使用v1.1.1-new
引用了new.com/workspace/a
。然而,这导致了以下错误:
go: new.com/workspace/a@v1.1.1-new: parsing go.mod:
module declares its path as: old.com/workspace/b
but was required as: new.com/workspace/b
如果我在仓库a
中检查v1.1.1-new
标签,可以看到go.mod
文件中的模块路径已正确设置为:
module new.com/workspace/a
我不清楚为什么在最新的提交上使用v1.2.3-new
标签时可以正常工作,但在引用旧提交时却失败了。
英文:
I recently had to move private repositories from SaaS Gitlab to an on-premise version. Everything was going well where I did:
- Update old go module paths in repo
a
fromold.com/workspace/a
tonew.com/workspace/a
- Add a new tag
v1.2.3-new
to the latest commit - Update repo
b
to reference latest tagv1.2.3-new
fromnew.com/workspace/a
- Run
go mod tidy
in repob
and verify it works
Now I have a requirement to reference an older version tag of new.com/workspace/a
(originally old.com/workspace/a
). So in repo a
, I checked out the older tag, fixed up the module path to new.com/workspace/a
from old.com/workspace/a
and tagged it as v1.1.1-new
.
In repo b
then I referenced new.com/workspace/a
with v1.1.1-new
. However, this results in:
go: new.com/workspace/a@v1.1.1-new: parsing go.mod:
module declares its path as: old.com/workspace/b
but was required as: new.com/workspace/b
If I check the v1.1.1-new
tag in repo a
, the module path is set correctly in the go.mod
file:
module new.com/workspace/a
It is unclear to me why it works with the tag v1.2.3-new
on the latest commit but fails when I reference an older commit.
答案1
得分: 1
所以我不能说我完全理解为什么这样做可以成功,但以下是使其成功的步骤(包括未成功的部分)。
-
我尝试使用
go clean -modcache
清除缓存。 -
使用以下命令进行测试,但仍然失败。
go get new.com/workspace/a@v1.1.1-new
-
根据我在原始问题中的评论,这通过
v1.1.1-new
提交哈希值成功。所以我再次尝试了这个方法。go get new.com/workspace/a@27ca81f7
现在它选择了该提交的版本,并且成功了。
go.mod
文件也正确地更新了标签/版本,尽管在go get
命令中使用了提交哈希值。new.com/workspace/a v1.1.1-new
英文:
So I can't say I fully understood why this worked but here are the steps that made it work (including what didn't).
-
I resorted to clearing the cache with
go clean -modcache
-
Tested with the following but it still failed.
go get new.com/workspace/a@v1.1.1-new
-
As per my comment in the original question, this worked via the
v1.1.1-new
commit hash So I resorted to that again.go get new.com/workspace/a@27ca81f7
Now it picked up the version for that commit and was successful. The
go.mod
file was also correctly updated with the tag/version despite
using the commit hash in thego get
command.new.com/workspace/a v1.1.1-new
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论