0

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?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
sasuke
  • 6,589
  • 5
  • 36
  • 35

2 Answers2

2

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 post
  • FETCH_HEAD - a short-lived ref, to keep track of what has been fetched from the remote repository
  • ORIG_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

enter image description here


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 ....

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    Nice, `git show HEAD --oneline` is what I was looking for. I would appreciate if you could mention this at the top of your answer since it is much better than `cat`ing around refs. But I do appreciate the depth provided. :) – sasuke Feb 25 '17 at 15:21
  • 1
    Better brief to different `HEAD`. +1 – Sajib Khan Feb 25 '17 at 15:26
  • 1
    If this is whats you was looking for please be kind to accept this answer. update as you requested. :-) – CodeWizard Feb 25 '17 at 15:30
2

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.

Community
  • 1
  • 1
dahlbyk
  • 75,175
  • 8
  • 100
  • 122