I want to check whether a particular Git commit sha1 exists on a specific remote. I tried the following command:
git fetch <remote> <revision> -q --dry-run
The problem is that the command returns success not only when the revision is present on the remote, but also when it is present locally.
Is there some way to check this ignoring the local revision?
If you have fetched all remote heads, you can try
$ git branch -r --contains <commit-sha>
This will give you a list of branches which contain the commit and you can see if the result includes remote ones.
If you want this to work without having fetched the remote, then a server-side config must be present: uploadpack.allowReachableSHA1InWant=true and the git versions of both server and client must be >= 2.5
Adding --depth=1 seems to work.
I can not explain why it works, and I could not find any mention of this in the documentation. Probably wouldn't rely on this if I needed a robust solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With