我无法使用 go.mod 通过使用具有
/v2
/ 主要版本映射的项目的任何固定分支来映射分叉。
我有以下 go.mod:
go 1.18
require (
github.com/versent/saml2aws/v2 v2.35.0
)
注意该模块需要
/v2
,否则会得到 v2.17.0+incompatible
。
add-aad-entropy-PhoneAppNotification
:https://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification
module github.com/versent/saml2aws/v2
到 module github.com/marcottedan/saml2aws/v2
我正在使用以下指令,但没有一个起作用:
这会下载我的叉子的标签
2.35.0
,即使我要求它获取 master
dmarcotte@dmarcottes% go get -d github.com/marcottedan/saml2aws/v2@master
go: downloading github.com/marcottedan/saml2aws/v2 v2.35.0
go: github.com/marcottedan/saml2aws/[email protected]: parsing go.mod:
module declares its path as: github.com/versent/saml2aws/v2
but was required as: github.com/marcottedan/saml2aws/v2
我也尝试修改我的
go.mod
:
replace github.com/versent/saml2aws/v2 => github.com/marcottedan/saml2aws/v2 v2.35.0
-> Can't find a way to target master with the /v2 pattern
如果我删除 /v2 并只使用@master,它不会关心并获取 v1 中的最新标签(在 saml2aws 迁移到 go mod 之前被命名为 2.17.0+不兼容)
dmarcotte@dmarcottes % go get -d github.com/marcottedan/saml2aws@master
go: github.com/marcottedan/saml2aws@master: github.com/marcottedan/[email protected]: invalid version: go.mod has post-v1 module path "github.com/marcottedan/saml2aws/v2" at revision f05a14a2b3f2
我在这里迷路了。
经过大量挖掘,以下是我发现似乎有效的步骤:
go.mod
第一行更改为您的新分叉名称,提交并推送go get -d -u github.com/marcottedan/saml2aws/v2@master
,其中@version 是您的分支名称。go.mod
中,添加以下替换指令:replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master
最后你的 go.mod 应该是这样的:
module <yourname>
go 1.18
require (
github.com/versent/saml2aws/v2 v2.35.0
)
replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master
请注意,如果您仅单独工作,则可以使用替换指令来映射驱动器上的本地文件夹。但这往往不适用于队友,因为他们在拉取代码时还必须检查相同的精确分叉路径。这是一个例子:
module <yourname>
go 1.18
require (
github.com/versent/saml2aws/v2 v2.35.0
)
replace github.com/versent/saml2aws/v2 => /Users/dmarcotte/git/saml2aws/
在解决同样的问题时,我发现 Go 更新了他们的替换指令。 丹尼尔的解决方案中的大部分步骤仍然有效。小事是 Go 不允许您在替换指令的末尾添加
branchname
。所以这是我采取的步骤:
git tag v0.0.1 && git push origin --tags
replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 v0.0.1
go get
。总而言之:
module <yourname>
go 1.18
require (
github.com/versent/saml2aws/v2 v2.35.0
)
replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 v0.0.1