gpt4 book ai didi

Go 项目不从 github 中提取导入更新

转载 作者:行者123 更新时间:2023-12-01 22:00:37 25 4
gpt4 key购买 nike

我有一个包裹 hello其中包含文件 go.modhello.go和一个包裹say_things带文件 go.modsay_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代码?

最佳答案

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

打开你的 go.mod文件在你的 hello项目和replace current version针对 github.com/user/say_things 写的使用您的 say_things 的最后一次提交哈希项目。

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

最后运行:

$ go mod tidy
$ go mod vendor

关于Go 项目不从 github 中提取导入更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63730319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com