【问题标题】:how to find out which git-branch a dependency in go.mod belongs to by command-line?如何通过命令行找出 go.mod 中的依赖项属于哪个 git-branch?
【发布时间】:2020-07-06 11:42:56
【问题描述】:

我想编写一个 shell 程序来检查我项目中的所有 go 模块依赖项是否都在其存储库中的最新主版本上。特别是,我想知道每个模块在哪个分支上。有一个文件“go.mod”,其中包含列为{module}-{commit time}-{commit ID} 的每个依赖项。如何从 SHA-1(commit id) 或 shell 程序的其他消息中获取他们的 git-branch 名称。

我尝试过go list -m -u all,仅在依赖项不是最新的情况下才显示最新版本。等等git.xxx.com/project v0.0.0-20191119034146-e894bf51bdcd [v0.0.0-20200609070643-fd412b12b811]。在不克隆 repos 的情况下,go 模块工具可以解决这个问题吗?

【问题讨论】:

  • 是什么让您认为 SHA 与任何分支名称相关联?还是只有一个?
  • 它是 Git 分支的提交 ID。现在的问题是如何在不克隆 repo 的情况下,通过 go tools 或其他命令行方法找到这个分支。

标签: go git-branch go-modules


【解决方案1】:

我无法弄清楚如何仅使用 go 工具来查找当前依赖项属于哪个分支。但是有一种方法可以使用 git 找到提交所在的分支。

git clone <repo-url> && cd <repo> && git branch -a --contains <commit>

参考:Finding what branch a Git commit came from

【讨论】:

    猜你喜欢
    • 2011-11-20
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 2019-07-04
    • 2016-07-27
    • 2011-05-20
    相关资源
    最近更新 更多