【问题标题】:Check whether two GitHub branches are "even" w/o local git repo?检查两个 GitHub 分支是否在没有本地 git repo 的情况下是“偶数”?
【发布时间】:2021-11-23 09:32:47
【问题描述】:

How can I check whether two branches are "even"? 描述了如何检查两个 git 分支是否是偶数。但是,答案依赖于分支提取和本地更新。由于这是脚本的一部分,而且 git repos 很大,我不想获取分支的所有信息。

如何检查 GitHub 存储库上的两个分支是否甚至没有 git 存储库的本地副本?

【问题讨论】:

  • 这不行:您想比较信息但不获取信息?我看到的唯一可能性是您将比较委托给某个已经拥有信息的系统。

标签: git github


【解决方案1】:

git ls-remote 将为您传递的任何引用打印远程存储库的提交哈希,而无需下载完整的历史记录,例如

git ls-remote origin master v1.0.0

可以打印:

cefe983a320c03d7843ac78e73bd513a27806845    refs/heads/master
f665776185ad074b236c00751d666da7d1977dbe    refs/tags/v1.0.0

从那里提取哈希值并进行比较。

ls-remote 甚至不需要本地 Git 存储库;只要您将有效的“远程”传递给它,您就可以从任何地方调用它:

git ls-remote git://git.kernel.org/pub/scm/git/git.git master v1.0.0

【讨论】:

  • 另一方面,它确实需要本地存储库,但我猜可能只是 git initgit origin add origin <url>
  • @Code-Apprentice 不一定,您也可以在本地仓库之外执行git ls-remote url-to-repo ref。感谢您的提问,我会在回答中澄清这一点。
猜你喜欢
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
相关资源
最近更新 更多