In brief you can commit the replace as long as you also commit the things it is redirecting to. We often do this to work on a package locally before pushing to github. You might also use it if you have modified an open source package but don't want to share the changes.
Originally, a common use for replace was for temporarily testing or trying an alternative version of a package. But many people were accidentally committing go.mod with the temporary replace clause so that is why Go 1.18 introduced the workspace file.
So use workspace for local temporary experiments. Use replace for (semi)permanent redirection. Always commit your go.mod file but never commit the workspace file.
This is my understanding. I'm sure someone will correct me if I'm wrong.
发布评论
评论(1)
简而言之,只要您也将其重定向的内容提交
替换
。我们经常这样做以在推到GitHub之前在本地处理包裹。如果您修改了开源软件包,但不想共享更改,也可以使用它。最初,替换的常见用途是用于临时测试或尝试替代版本的软件包。但是许多人意外地使用了
go.mod
使用临时替换
子句,因此这就是为什么go 1.18介绍了工作空间文件的原因。因此,请使用
工作区
进行本地临时实验。使用替换(半)永久重定向
。始终提交您的go.mod文件,但永远不要提交工作区文件。这是我的理解。我敢肯定,如果我错了,我会纠正我。
In brief you can commit the
replace
as long as you also commit the things it is redirecting to. We often do this to work on a package locally before pushing to github. You might also use it if you have modified an open source package but don't want to share the changes.Originally, a common use for replace was for temporarily testing or trying an alternative version of a package. But many people were accidentally committing
go.mod
with the temporaryreplace
clause so that is why Go 1.18 introduced the workspace file.So use
workspace
for local temporary experiments. Usereplace
for (semi)permanent redirection. Always commit your go.mod file but never commit the workspace file.This is my understanding. I'm sure someone will correct me if I'm wrong.