git rev-parse
A low-level command that turns a name such as HEAD, main or HEAD~1 into an object ID, and answers questions about the repository.
In more detail
git rev-parse HEAD prints the full ID of the current commit and --short abbreviates it. --show-toplevel prints the root folder of the repository you are in, and --show-prefix prints where you are relative to that root. Scripts use it to get exact answers instead of parsing other output.
Examples
git rev-parse --show-toplevelgit rev-parse main featureRelated terms
- object ID — The hash that names a Git object, such as a commit, and that you type to refer to it.
- revision — Any expression Git accepts as a name for a commit or other object, such as an ID, a branch name, a tag, HEAD or HEAD~2.
- repository root — The top folder of a repository's working tree, the one that contains the .git directory.
Taught in
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- What A Commit Really Is — Advanced Git Internals & Distributed Workflows
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- HEAD, And Why Detached HEAD Is Not An Error — Advanced Git Internals & Distributed Workflows
- Merging: Fast Forward Or A Merge Commit — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows