简体   繁体   English

如何检查远程Git存储库中是否存在修订(提交)

[英]How to check if the revision(commit) exists in a remote Git repository

I'm working on application that deploys other applications from git repo to server and there is an option where user can choose which revision to deploy. 我正在开发将其他应用程序从git repo部署到服务器的应用程序,并且有一个选项,用户可以选择要部署的修订版本。

My problem is to validate revision exists in given repo without downloading it . 我的问题是验证修订是否存在于给定的repo 而不下载它

In similar question they recomend to use test $(git cat-file -t $sha) == commit but it needs local repo. 类似的问题中,他们建议使用test $(git cat-file -t $sha) == commit但它需要本地repo。

Is it possible to check revision exists on remote repo by its URL? 是否可以通过URL检查远程仓库中是否存在修订?

Your question depends on what you mean by revision(commit) 你的问题取决于你的修订意义(提交)

If you mean "reference" (eg tag or branch) then you can use git-ls-remote to check if a repository has it without downloading it. 如果您的意思是“引用”(例如标记或分支),那么您可以使用git-ls-remote来检查存储库是否有它而不下载它。

If you mean "commit id" (eg SHA) then it depends if that commit is head of a current reference in the remote repository. 如果您的意思是“提交ID”(例如SHA),那么它取决于该提交是否是远程存储库中当前引用的头部 If so then 'git ls-remote --heads --tags' will show the SHAs of the current heads, for example using the command line: 如果是这样,那么'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

If however that SHA is not at the head of a reference (ie is an ancestor), then you would need to download ( clone and/or fetch as needed). 但是,如果SHA不在引用的头部(即是祖先),那么您需要下载(根据需要克隆和/或获取 )。 See this discussions in running git-merge on a remote for more background. 有关更多背景信息,请参阅在远程控制器上运行git-merge的此讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM