Search code examples
gitcommitcontains

Determining if a Git repository contains a particular commit


I'd like to determine whether a remote git repository (origin) contains a particular commit. My use case follows:

I'm preparing to create a public release. I want to include the SHA-1 of the commit representing the pristine codebase from which I am building the release.

I also want to insure that the commit is not just a local commit, but that it has in fact been pushed to a central repository (origin).

I think


git pull --all & git branch --contains commit-hash

and then examining the output to see if it contains the current branch's tracking branch, works, but seems rather cumbersome. I'm looking for something a little more succinct such as git remote --contains origin commit-hash, or git cat-file origin commit-hash. I figure there has to be some plumbing command that Git uses when determining which objects need to be transferred during a push or pull - I'm just not familiar enough with the internals.

Thanks for the help.


Solution

  • How about: git fetch && git branch -r --contains <commit-id>