Skip to content
The Git Crypt

/static/cripta/en/ossada/rev-parse/

Menu

GIT-012 · Plumbing

git rev-parse

Translates any name — HEAD~3, @{u}, main — into the hash git understands.

Git's entire grammar of names — HEAD~3, main@{u}, :/message — goes through a translator before becoming a hash. rev-parse is that translator, exposed: a name goes in, the exact address in the object vault comes out.

In scripts, it is the pocketknife: --show-toplevel finds the repository root, --abbrev-ref HEAD names the current branch, --verify fails loudly when the reference doesn't exist. Half of all shell scripting over git starts here.

$ git rev-parse --short HEAD~2
da0f3e6
$ git rev-parse --show-toplevel
/Users/andrey/Code/stickybit
Two names translated: a commit and the site's root.