-vilkw
Last Updated: February 25, 2016
·
3.247K
· ihcsim
130921 tcl 103 s

Git: Tree-ish

Tree-ish is a way to refer to particular commits in Git using either full or partial hash of the commits, refs, branch, remotes, or a combination of these with those ^, ~, @ characters. I am still new to these, so appreciate any additions and corrections.

Reference: http://git-scm.com/book/en/Git-Tools-Revision-Selection

  • Full hash:

    git show a5bec062afe1348b8317651c93cf5049e6b4e55e
  • Partial hash:

    git show a5bec
  • Some example of using refs (it's really anything you can find in .git/refs):

    git show HEAD
    git show FETCH_HEAD
    git show ORIG_HEAD
    git show MERGE_HEAD 
  • Caret (^) - number of ancestors before a given commit:

    git show HEAD^   # direct parent of HEAD
    git show a5bec^^ # two commits before 
  • Tildes (~) - number of commit to go back:

    git show HEAD~6  # 6 commits before HEAD
  • Ordinal (@{n}):

    git reflog {ref} # shows a log of where your ref has been
    git show HEAD@{0}   # current HEAD
    git show HEAD@{2}   # second prior value of HEAD
    git show master@{0}  # current master
    git show master@{yesterday}  # where master was yesterday
    git show master@{1.week.ago} # where master was a week ago
Say Thanks
Respond
Filed Under