GO项目不从GitHub汲取导入更新 我有一个包装hello,其中包含文件go.mod and hello.go,以及一个带有文件go.mod and say_things.go的软件包say_things。 hello.go: 包装主 导入“github.com/user/say_things&quo...

问题描述 投票:0回答:2
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 versioning dependency-management go-modules
2个回答
4
投票
必须 适用于

语义版本规范)

% 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

3
投票
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>
我可以猜测如果您想要其他分支,则将其放在那里。
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.