How to validate whether the commit with given sha exists in current branch?
There are many ways to parse outputs, but I need optimal way which returns boolean (for u
git merge-base --is-ancestor $sha HEAD
This tests if $sha is an ancestor commit for the current branch (HEAD), and exits successfully if it is.
$sha
HEAD
In your example,
sha=$1 if ! git merge-base --is-ancestor $sha HEAD; then echo "Invalid commit sha: $sha" exit 1 fi