【问题标题】:How to check if the revision(commit) exists in a remote Git repository如何检查远程 Git 存储库中是否存在修订(提交)
【发布时间】:2016-05-11 10:25:18
【问题描述】:

我正在开发将其他应用程序从 git repo 部署到服务器的应用程序,并且有一个选项可供用户选择要部署的修订版。

我的问题是验证给定仓库中是否存在修订无需下载

similar question,他们建议使用test $(git cat-file -t $sha) == commit,但它需要本地回购。

是否可以通过 URL 检查远程 repo 上是否存在修订?

【问题讨论】:

    标签: git


    【解决方案1】:

    您的问题取决于您所说的 revision(commit)

    的含义

    如果您的意思是“参考”(例如标签或分支),那么您可以使用git-ls-remote 来检查存储库是否有它而不下载它。

    如果您的意思是“提交 ID”(例如 SHA),那么 这取决于该提交是否是远程存储库中当前引用的头。如果是这样,那么 'git ls-remote --heads --tags' 将显示当前头的 SHA,例如使用命令行:

    $ git ls-remote --heads --tags origin
    From git@git.company.com:proj/path
    05f1351c4d2aef79e0f52ef32868f5f56e4bf264        refs/heads/dev
    2e5df15c40441428c8c0a622bfd8c59d124fc9c7        refs/heads/master
    05e1351f4d2aef79e0f522f33868f5f56e4bf264        refs/heads/prod
    05e1351f4d2aef79e0f522f33868f5f56e4bf264        refs/heads/stage
    05e1351f4d2aef79e0f522f33868f5f56e4bf264        refs/heads/test
    

    但是,如果 SHA 不在引用的开头(即是祖先),那么您需要下载(clone 和/或 fetch 根据需要)。有关更多背景信息,请参阅 running git-merge on a remote 中的讨论。

    【讨论】:

      猜你喜欢
      • 2012-05-09
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      相关资源
      最近更新 更多