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

我有一个hello包含文件go.mod和hello.go的包,以及一个say_things包含文件go.mod和say_things.go.


hello.go:


package main


import "github.com/user/say_things"


func main() {

        say_things.SayBye()

}

say_things.go:


package say_things


import "fmt"


func SayBye() {

        fmt.Println("BYE")

}

这两个项目都是 github 项目。当我运行时hello.go,它会按预期打印“BYE”。我现在更新SayBye为:


package say_things


import "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代码?


呼如林
浏览 215回答 2
2回答

皈依舞

一种通过执行以下更改来更新代码的方法。在您的项目中打开您的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>最后运行:$&nbsp;go&nbsp;mod&nbsp;tidy $&nbsp;go&nbsp;mod&nbsp;vendor

守候你守候我

go get命令下载所需模块的新版本。例如:% go get -u allgo: 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.1git pushgit push --tags&nbsp;这将允许您手动更改版本go.modmodule github.com/user/hellogo 1.15require github.com/user/say_things v1.0.1% go mod download&nbsp;go: finding github.com/user/say_things v1.0.1, 并通过版本标签获取所需版本% go get github.com/user/say_things@v1.0.1go: finding github.com/user/say_things v1.0.1go: downloading github.com/user/say_things v1.0.1go: extracting github.com/user/say_things v1.0.1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go