Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

My problem is to validate revision exists in given repo without downloading it.

In similar question they recomend to use test $(git cat-file -t $sha) == commit but it needs local repo.

Is it possible to check revision exists on remote repo by its URL?

like image 238
Manasov Daniel Avatar asked Nov 09 '22 20:11

Manasov Daniel


1 Answers

Your question depends on what you mean by revision(commit)

If you mean "reference" (e.g. tag or branch) then you can use git-ls-remote to check if a repository has it without downloading it.

If you mean "commit id" (e.g. SHA) then it depends if that commit is head of a current reference in the remote repository. 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 origin
From [email protected]: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 (i.e. is an ancestor), then you would need to download (clone and/or fetch as needed). See this discussions in running git-merge on a remote for more background.

like image 126
qneill Avatar answered Nov 15 '22 05:11

qneill