I need a command which returns the full reference name of my currently checked out revision. Or as close to this as possible. Big plus if git-only (for cross-platform purposes).
By "full reference name" I mean e.g. refs/tags/my-tag
, refs/heads/my-branch
.
Examples:
git checkout master
magic command
# => /refs/heads/master
git checkout v1.0.0
magic command
# => /refs/tags/v1.0.0
git checkout 86742545e8152a8fbf31eafa55eb573042f61f5d
magic command
# =>
Few points of reference:
- I actually don't think this is possible with 100% accuracy because (as I understand git) there's no difference between checking out a tag and a specific hash. I.e.
.git/HEAD
shows the hash in both cases. git show-ref
shows all references and the corresponding commit hashesgit symbolic-ref HEAD
works for branches and with the-q
option it doesn't fail if you're not on a branchgit describe --tags --exact-match
kind of works for tags, but you'd need to prefix it withrefs/tags
and get rid of stderr
Related:
All I could find seemed too complicated for what I'm looking for.