Git - git show

git

What is the purpose of the 'git show' command?

show commit info, diffstat and patch of the tip of the current branch

git show HEAD
git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7

Git do not use numeric revision number like Subversion. The above long string is the equivalent of a revision number in Subversion. I am not quite sure why Git use this long string yet.

You can use any initial part of the name that is long enough to uniquely identify the commit:

git show c82a22c39c   # the first few characters of the name are
                        # usually enough
git show HEAD         # the tip of the current branch
git show experimental # the tip of the "experimental" branch

Every commit usually has one "parent" commit which points to the previous state of the project:

git show HEAD^  # to see the parent of HEAD
git show HEAD^^ # to see the grandparent of HEAD
git show HEAD~4 # to see the great-great grandparent of HEAD

Note that merge commits may have more than one parent:

git show HEAD^1 # show the first parent of HEAD (same as HEAD^)
git show HEAD^2 # show the second parent of HEAD

How can we use git show?

# relative to a name
git show master^   # show parent to last revision of master
git show master~2  # show grand parent to tip of master
git show master~3  # show great grand parent to tip of master (you get the idea)

# by hash (internally, all objects are identified by a hash)
git show f665776185ad074b236c00751d666da7d1977dbe
git show f665776   # a unique prefix is sufficient

How can we show the content of a particular file or directory at a particular revision?

git show rev
git show rev:path/to/file
git show rev:path/to/directory

How can we see the tag data and corresponding commit?

git show v2.0
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License