Added support for git name-rev.

This results in friendlier names when we do not have a branch checked
out. e.g. master~2.
In order to distinguish between checking out a branch and checking out a
commit corresponding to the branch (i.e. a detached head), we prefix
these names with hashes. Commit hashes use the same prefix for
consistency.