导入软件包的本地更改而无需在Golang中推送代码 [英] Importing local changes of a package without pushing code in Golang
问题描述
我现在正在学习Golang和一个新手.我对包裹有疑问.
I' am learning Golang now-a-days and a total newbie. I have a question regarding packages.
请考虑以下情形:
想象一下,我有一个软件包 github.com/ilatif/A
,其中我正在导入另一个软件包 github.com/ilatif/B
,例如:
Imagine I have a package github.com/ilatif/A
in which I' am importing another package github.com/ilatif/B
, like:
导入"github.com/ilatif/B"
现在,由于 github.com/ilatif/A
和 github.com/ilatif/B
都是我的软件包,而我正在本地处理它们,从 github.com/ilatif/B
包中提取更改而无需将代码推送到GitHub的方法?根据Golang的文档,我需要将代码推送到相关的存储库中,但是我想知道是否存在一种方法,可以在不首先将其推送到上游的情况下提取我自己的软件包的本地更改.
Now since both github.com/ilatif/A
and github.com/ilatif/B
are my packages and I' am working locally on them, is there a way to pull changes from github.com/ilatif/B
package without pushing code to GitHub? As per Golang's documentation, I need to push the code to its relevant repo but I was wondering if there is such a way to pull local changes of my own package without pushing it to upstream first.
谢谢
推荐答案
Go模块解决方案
通过在文件 go.mod
中使用replace,我可以成功地将Golang与模块一起使用.
Go Module Solution
I could successfully use Golang with modules by using replace in the file go.mod
.
https://thewebivore.com/using-replace-in-go-mod-point-to-您的本地模块/
- 使用
replace
语句保存go.mod
文件后,Goland就会识别出更新的模块.
- As soon as you save the
go.mod
file with thereplace
statement, Goland recognizes the updated module.
- 使用
替换MODULE_URL =>/PATH/TO/MODULE/DIR
- 无需指定版本
module github.x.com/services-x/x go 1.13 require ( github.com/briandowns/spinner v1.8.0 github.com/golang/protobuf v1.3.1 github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8 github.com/marcellodesales/cloner v0.0.0-20191126082454-c952bef1e067 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.1.2 github.com/sirupsen/logrus v1.2.0 github.com/spf13/cobra v0.0.5 github.com/spf13/viper v1.4.0 github.com/thoas/go-funk v0.4.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/yaml.v2 v2.2.2 ) replace github.com/marcellodesales/cloner => /Users/mdesales/dev/github.com/marcellodesales/cloner
这篇关于导入软件包的本地更改而无需在Golang中推送代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!