douxi3404
2019-08-06 16:55
浏览 1.1k
已采纳

如何使用Go模块在特定分支上导入软件包

I'm reorganizing a repo from the following structure:

repo_root/
   |- foo/
       |- foo.go
   |- bar/
       |- bar.go
   |- go.mod

into the following:

repo_root/
   |- gosrc/
        |- foo/
             |- foo.go
        |- bar/
             |- bar.go
        |- go.mod

Now, inside foo.go of the original repo structure, I do something like below to import the package bar:

import "github.com/arb_name/repo_root/bar"

Now, with the new repo, I changed it to:

import "github.com/arb_name/repo_root/gosrc/bar"

Now, I run into the problem that go build of foo.go failed because

cannot find module providing package github.com/arb_name/repo_root/gosrc/bar

I certainly do not want to change the master branch of repo without first making sure that the restructure of repo works. I'm wondering if there is a way to solve my situation? I can work on my fork but ideally not directly making change to my fork's master.

Thanks!

图片转代码服务由CSDN问答提供 功能建议

我正在根据以下结构重组存储库:

  repo_root / 
 |-foo / 
 |-foo.go 
 |-bar / 
 |-bar.go 
 |-go.mod 
   
 
  

进入以下内容:

  repo_root / 
 |-gosrc / 
 |-foo / 
 |-foo.go 
 |-bar / 
  |-bar.go 
 |-go.mod 
   
 
 

现在,在原始回购结构的 foo.go 中, 如下所示,导入软件包 bar

  import“ github.com/arb_name/repo_root/bar"
 
 
 

现在,使用新的存储库,我将其更改为:

  import“ github.com/arb_name/repo_root/gosrc/bar” \  n   
 
 

现在,我遇到的问题是,由于 foo.go go build 失败了

找不到提供软件包github.com/arb_name/repo_root/gosrc/bar

的模块我当然不想要 更改回购主分支,而无需先确保回购的重组工作正常。 我想知道是否有办法解决我的情况? 我可以使用叉子,但理想情况下不能直接更改叉子的母版。

谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题