为了账号安全,请及时绑定邮箱和手机立即绑定

Go 项目不从 github 拉取导入更新

Go 项目不从 github 拉取导入更新

Go
呼如林 2022-06-27 15:42:20
我有一个hello包含文件go.mod和hello.go的包,以及一个say_things包含文件go.mod和say_things.go.hello.go:package mainimport "github.com/user/say_things"func main() {        say_things.SayBye()}say_things.go:package say_thingsimport "fmt"func SayBye() {        fmt.Println("BYE")}这两个项目都是 github 项目。当我运行时hello.go,它会按预期打印“BYE”。我现在更新SayBye为:package say_thingsimport "fmt"func SayBye() {        fmt.Println("GO AWAY")}并将更改推送到 github。我再次跑hello.go,期待它说“走开”,但事实并非如此。它仍然说BYE。我再次删除go.sum生成的go run hello.go,但仍然显示BYE. 然后我去go/pkg/mod/github.com/user/并删除say_bye@v0.0.0-<hash>,然后hello.go再次运行。尽管如此,什么都没有改变。接下来,我运行go get github.com/user/say_things,我仍然得到BYE。如何hello.go运行更新的say_hello代码?
查看完整描述

2 回答

?
皈依舞

TA贡献1851条经验 获得超3个赞

一种通过执行以下更改来更新代码的方法。

在您的项目中打开您的go.mod文件,并使用项目的最后一个提交哈希写入。helloreplacecurrent versiongithub.com/user/say_thingssay_things

换句话说,在go.mod文件中
替换github.com/user/say_things <current-version>
github.com/user/say_things <last-commit-hash>

最后运行:

$ go mod tidy
$ go mod vendor


查看完整回答
反对 回复 2022-06-27
?
守候你守候我

TA贡献1802条经验 获得超10个赞

go get命令下载所需模块的新版本。例如:


% go get -u all


go: github.com/user/say_things upgrade => v0.0.0-<new hash>

– 将所有最后一个模块的版本下载到$GOPATH/pkg升级go.mod文件。


❕使用go-modules时,更好的方法是向存储库添加版本标签(tag必须符合语义版本控制规范)


git commit -a - m "say_things - some changes"

git tag v1.0.1

git push

git push --tags 

这将允许您手动更改版本go.mod


module github.com/user/hello


go 1.15


require github.com/user/say_things v1.0.1

% go mod download 


go: finding github.com/user/say_things v1.0.1

, 并通过版本标签获取所需版本


% go get github.com/user/say_things@v1.0.1


go: finding github.com/user/say_things v1.0.1

go: downloading github.com/user/say_things v1.0.1

go: extracting github.com/user/say_things v1.0.1


查看完整回答
反对 回复 2022-06-27
  • 2 回答
  • 0 关注
  • 214 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号