簡體   English   中英

如何將主要版本的 Go Module 替換為 fork @ master

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

我在使用帶有/v2 / 主要版本映射的項目的 go.mod 的任何固定分支映射分叉時遇到問題。

我有以下 go.mod:

go 1.18

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

注意該模塊需要/v2 ,否則它會得到v2.17.0+incompatible

  1. 我在這里分叉了這個項目: https ://github.com/marcottedan/saml2aws
  2. 我在這里創建了一個分支add-aad-entropy-PhoneAppNotificationhttps://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification ://github.com/marcottedan/saml2aws/tree/add-aad-entropy-PhoneAppNotification
  3. 我嘗試修改或不修改我的 fork go mod 中 go.mod 的第一行,從module github.com/versent/saml2aws/v2module github.com/marcottedan/saml2aws/v2

我正在使用以下指令,但沒有一個有效:

這會下載我 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

我還嘗試修改我的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+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

我在這里很迷茫。

經過大量挖掘,以下是我發現似乎有效的步驟:

  1. 創建任何項目的分支
  2. go.mod第一行更改為您的新分叉名稱,提交和推送
  3. 在分支或主控中提交並推送您需要的任何更改
  4. 在您的原始項目中,執行以下命令: go get -d -u github.com/marcottedan/saml2aws/v2@master其中@version 是您的分支名稱。
  5. 在您的go.mod中,添加以下替換指令: replace github.com/versent/saml2aws/v2 v2.35.0 => github.com/marcottedan/saml2aws/v2 master
  6. 每次在 fork 中推送提交時,重復第 4 步。

最后你的 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

請注意,如果您只是單獨工作,則可以使用 replace 指令映射驅動器上的本地文件夾。 但這往往不適用於隊友,因為他們在提取代碼時還必須檢查相同的確切分叉路徑。 這是一個例子:

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