Go學習筆記 製作一個能被世界人民使用的工具包!
阿新 • • 發佈:2021-01-24
技術標籤:Go學習筆記
- 在github上建立一個公共庫
- 將公共庫使用git關聯到本地專案
git init
git add .
git commit -m '提交資訊'
// 將本地倉庫與遠端倉庫繫結(地址為遠端倉庫的地址)
git remote add origin https://github.com/mushi/test.git
git push origin master
PS:
在這過程中你可能會遇到"fatal: refusing to merge unrelated histories
"的問題,你可以參考解決方案
-
使用
go mod init github.com/mushi/test
PS:
包的命名很重要,這關係到之後使用go get github.com/mushi/test
命令是否能找到你的工具包 -
將程式碼更新到遠端庫後,別以為這樣就vans了,此時還是go get不到你的工具包,會報以下錯誤
module declares its path as: github.com/mushi/test
but was required as: github.com/mushi/test
這是因為你的包沒有設定版本號導致的,此時你只需要新增版本號
git tag v0.0.1
git push --tags
PS:
版本號一定要嚴格遵守vX.Y.Z的格式,vX.Y什麼的少一個數都不行,會導致版本指定無效
- 當你想刪除不需要的版本時,只需要執行以下git命令即可
git tag -d [tag];
git push origin :[tag]