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
这些项目都是GitHub项目。当我运行
package say_things
import "fmt"
func SayBye() {
fmt.Println("BYE")
}
时,它会按预期打印“再见”。我现在更新为:
hello.go
将更改推向github。我再次运行
SayBye
,期望它说“走开”,但事实并非如此。它仍然说
package say_things
import "fmt"
func SayBye() {
fmt.Println("GO AWAY")
}
。我删除了hello.go
产生并再次删除,但仍然说BYE
。然后,我去
go.sum
删除
go run hello.go
,然后再次运行BYE
。尽管如此,什么都没有改变。接下来,我跑了go/pkg/mod/github.com/user/
,我仍然得到[email protected]<hash>
。
我如何获得更新的
hello.go
代码?
GOGET命令下载新版本的必需模块。 例如:
go get github.com/user/say_things
–将所有最后一个模块的版本下载到BYE
和升级
hello.go
文件。
❕当使用Go-modules时,更好的方法是将版本标签添加到存储库中(
语义版本规范)
% go get -u all
go: github.com/user/say_things upgrade => v0.0.0-<new hash>
这将允许您手动更改版本$GOPATH/pkg
go.mod
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
项目的最后一个提交hash写成% go get github.com/user/[email protected]
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
在其他单词中,在
go.mod
文件中 更换
hello
replace
current version
最终运行:
github.com/user/say_things
这让我发疯的时间比应该的时间更长,建议的答案对我有用,但这确实如此:i我正试图
say_things
我刚刚推动的一个软件包,但是在我运行go.mod
命令github.com/user/say_things <current-version>
时,该软件包才会更新,然后将其附加到repo链接的末尾,喜欢:
github.com/user/say_things <last-commit-hash>