亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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/并刪除[email protected]<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/[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


查看完整回答
反對 回復 2022-06-27
  • 2 回答
  • 0 關注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號