Fix retrieval method for commit number

It now works even if the tagged commit is on a different branch than the
currently checked out branch.