Chris
Chris

Reputation: 4774

Checking whether a commit hash has already been deployed in git

Let's say I have an online app that has been deployed with a specific commit hash (i.e. git checkout commitHash).

And given a specific branch, I wanted to check whether another commit hash comes before the deployed commit hash. What would be the best way to do it? Is there a git command or shell script where I can provide both hashes and it can tell me?

Context: I'm essentially wanting to check whether a specific commit hash has been deployed or not for a specific environment.

Upvotes: 2

Views: 730

Answers (1)

Klas Mellbourn
Klas Mellbourn

Reputation: 44347

You could use git log with .. notation.

git log <hashA>..<hashB>

This will give output if <hashA> is before <hashB> but it will have no output if <hashB> is before <hashA>. (This is assuming, as in your case, that the revisions are on the same branch).

To be more formal, <hashA>..<hashB> includes commits that are reachable (via parent references) from <hashB> but excludes those that are reachable from <hashA>. The gitrevisions man page has more information.

Upvotes: 4

Related Questions