In case it is not sure if a specific commit is part of a git tag or another git commit or even main or master branches,
the following command gives an overview of the situation.
This can be particularly useful if it is required to know if a commit is part of a specific release.
Imagine git commit hash 6808820 is the commit we want to check.
Let's further imagine commit hash 163d5c6da7090ef7df492497b93b6854ac2660ac represents a certain point in history.
The question is whether commit 6808820 is contained in the history of commit 163d5c6da7090ef7df492497b93b6854ac2660ac:
# The command only returns '1' or '0', using 'echo' gives a visual result.
git merge-base --is-ancestor 6808820 163d5c6da7090ef7df492497b93b6854ac2660ac && echo "yes" || echo "no"
# The same check against 'main'.
git merge-base --is-ancestor 6808820 163d5c6da7090ef7df492497b93b6854ac2660ac && echo "yes" || echo "no"
Possible output for both commands above:
* yes: 6808820 is part of the history.
* no: 6808820 is not part of the history.
The next command lists the first tag/release that contains the commit hash 6808820:
git tag --contains 6808820 --sort=creatordate | head -1