Git provides "friendly names" for referencing some frequently used commit hashes like HEAD
, ORIG_HEAD
, FETCH_HEAD
, MERGE_HEAD
.
I was wondering if there is a standard way of printing what these friendly identifiers point to?
Git provides "friendly names" for referencing some frequently used commit hashes like HEAD
, ORIG_HEAD
, FETCH_HEAD
, MERGE_HEAD
.
I was wondering if there is a standard way of printing what these friendly identifiers point to?
All the above files are simple a metadata of git.
HEAD
- The current commit in the current branch points to. To fully understand what HEAD
is read this detaled postFETCH_HEAD
- a short-lived ref, to keep track of what has been fetched from the remote repositoryORIG_HEAD
- previous state of HEAD
MERGE_HEAD
- records the commit(s) which you are merging into your branch when you run git merge.CHERRY_PICK_HEAD
records the commit which you are cherry-picking when you run git cherry-pick.You can always use simple cat file:
cat .git/HEAD
cat .git/FETCH_HEAD
You can use any of the above to view the content of the commit with the git show
command. This will print out the content of the commit.
# To view the latest commit message
git show HEAD --oneline
# To view the latest commit content
git show HEAD
and so on ....
git rev-parse <anything>
will try to resolve a commit.
As @CodeWizard notes, you can also inspect the contents of those files under .git/
to see how they work.