du13932014807 2019-08-22 13:38
浏览 266
已采纳

Go模块替换为本地模块的特定版本

I have a go.mod file that looks like this:

module someName

go 1.13

require (
    .
    .
    golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
    localpackage v0.0.0
)

replace localpackage => ../localpackage

This works just as expected! What I can't figure out is how can I add a certain version or commit hash to the replace directive!

For example:

replace localpackage => ../localpackage v1.0.0

or

replace localpackage => ../localpackage v0.0.0-20190731182444-35453ccff3d6

Doing this results in an error:

replacement module directory path "../localpackage" cannot have version

The error is quite clear that I shouldn't add a version to a local replace. I checked the wiki but I couldn't find an answer!

The question:

Is it possible to add this kind of replacement and how? What am I missing here?

  • 写回答

1条回答 默认 最新

  • douying4203 2019-08-22 14:09
    关注

    As the error says: you cannot specify a version when the replace directive is pointed at a local folder. There is no guarantee and it is not a requirement that the replacement folder contains files of a versioning system, it is perfectly valid to just have "snaphots" of the Go sources. So in many cases it would have no meaning to specify a version.

    However, if your local folder is a clone of a git repository for example, you may simply switch that to your intended version. E.g. execute a git checkout v1.0.0 in that local folder to switch to that version, and that version will be used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。