Git: Commit Referencing Syntax

There are a couple of different ways to refer to a commit:

  1. Full SHA: 7fa145658ded8b44c3df134c3161c21df9b0ad4b
  2. Abbreviated SHA: 7fa145
  3. Branch name: branch-name
  4. Reflog
    • Previous HEAD: HEAD@{1}
    • Five HEADs ago: HEAD@{5}
    • HEAD yesterday: HEAD@{yesterday}
  5. Parent: 7fa145^
  6. Parent of parent: 7fa145^^ or 7fa145~2
  7. 5 parents “above” current commit: 7fa145^^^^^ or 7fa145~5

Similarly for a range of commits:

  1. Commits reachable from branch-a but not from branch-b: branch-b..branch-a or ^branch-b branch-a
  2. Commits reachable from branch-a and branch-b, but not from branch-c: branch-a branch-b ^branch-c
  3. Commits reachable from branch-a or branch-b (but not both): branch-b...branch-a (use --left-right to disambiguate)