简体   繁体   English

如何将主要版本的 Go Module 替换为 fork @ master

[英]How to replace a Go Module with a major version to a fork @ master

I have trouble mapping a fork through any pinned branch with go.mod that use a project with the /v2 / major version mapping.我在使用带有/v2 / 主要版本映射的项目的 go.mod 的任何固定分支映射分叉时遇到问题。

I have the following go.mod:我有以下 go.mod:

go 1.18

require (
    github.com/versent/saml2aws/v2 v2.35.0
)

Notice the module requires the /v2 , otherwise it would get v2.17.0+incompatible .注意该模块需要/v2 ,否则它会得到v2.17.0+incompatible

  1. I forked the project here: https://github.com/marcottedan/saml2aws我在这里分叉了这个项目: https ://github.com/marcottedan/saml2aws
  2. I created a branch add-aad-entropy-PhoneAppNotification here: https://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification我在这里创建了一个分支add-aad-entropy-PhoneAppNotificationhttps://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification ://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification
  3. I tried to modify, or not, the first line of go.mod in my fork go mod from module github.com/versent/saml2aws/v2 to module github.com/marcottedan/saml2aws/v2我尝试修改或不修改我的 fork go mod 中 go.mod 的第一行,从module github.com/versent/saml2aws/v2module github.com/marcottedan/saml2aws/v2

I'm using the following directives and none are working:我正在使用以下指令,但没有一个有效:

This downloads the tag 2.35.0 of my fork even though I ask it to get master这会下载我 fork 的标签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/v2@v2.35.0: parsing go.mod:
        module declares its path as: github.com/versent/saml2aws/v2
                but was required as: github.com/marcottedan/saml2aws/v2

I also tried modifying my go.mod :我还尝试修改我的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

If I drop the /v2 and just go with @master, it doesn't care and get the latest tag in v1 (which was named 2.17.0+incompatible before saml2aws migrated to go mod)如果我放弃 /v2 并使用 @master,它并不关心并获取 v1 中的最新标签(在 saml2aws 迁移到 go mod 之前,它被命名为 2.17.0+incompatible)

dmarcotte@dmarcottes % go get -d github.com/marcottedan/saml2aws@master   
go: github.com/marcottedan/saml2aws@master: github.com/marcottedan/saml2aws@v1.8.5-0.20220520001825-f05a14a2b3f2: invalid version: go.mod has post-v1 module path "github.com/marcottedan/saml2aws/v2" at revision f05a14a2b3f2

I'm quite lost here.我在这里很迷茫。

After a lot of digging, here are the steps I found that seem to be working:经过大量挖掘,以下是我发现似乎有效的步骤:

  1. Create a fork of any project创建任何项目的分支
  2. Change the go.mod first line to your new fork name, commit & pushgo.mod第一行更改为您的新分叉名称,提交和推送
  3. Commit&Push any change you need, in a branch or in master在分支或主控中提交并推送您需要的任何更改
  4. In your original project, do the following command: go get -d -u github.com/marcottedan/saml2aws/v2@master where the @version is your branch name.在您的原始项目中,执行以下命令: go get -d -u github.com/marcottedan/saml2aws/v2@master其中@version 是您的分支名称。
  5. In your go.mod , add the following replace directive: replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master在您的go.mod中,添加以下替换指令: replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master
  6. Every time you push a commit in your fork, repeat step 4.每次在 fork 中推送提交时,重复第 4 步。

At the end your go.mod should look like this:最后你的 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

Note that if you're only working in solo, you can use the replace directive to map a local folder on your drive.请注意,如果您只是单独工作,则可以使用 replace 指令映射驱动器上的本地文件夹。 But this tend to not work well with teammates since they must also have the same exact fork path checked out while pulling the code.但这往往不适用于队友,因为他们在提取代码时还必须检查相同的确切分叉路径。 Here's an example:这是一个例子:

module <yourname>

go 1.18

require (
    github.com/versent/saml2aws/v2 v2.35.0
)

replace github.com/versent/saml2aws/v2 => /Users/dmarcotte/git/saml2aws/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM