A list of revision specifications you can use with git log and many other Git commands. Summarized from gitrevisions(7) man page.

Example usages

ExampleDescription
git log master...developinspect differences in branches
git rebase -i HEAD~3rebase last 3 commits
git reset --hard HEAD@{2}undo last operation that changed HEAD
git checkout v2^{}checkout the v2 tag (not v2 branch)

The 3rd argument in each of these commands is a gitrevision. These gitrevisions can be passed to many Git commands.

Common git revisions

ReferenceDescription
git show dae68e1sha1
git show HEADreference
git show v1.0.0tag
git show masterlocal branch
git show origin/masterremote branch
git show master~22 commits back from master
git show master..fixreachable from fix but not master
git show master...fixreachable from fix and master, but not both

These are just the common ones, there's a lot more below! (These work in many other commands, not just git show.)

Reference

Commits

ReferenceDescription
git checkout dae68e1sha1

References

ExampleDescription
git checkout HEADreference
git checkout masterbranch
git checkout v1.0.0tag
git checkout origin/masteraka, refs/remotes/origin/master
git checkout heads/masteraka, refs/heads/master

Searching back

ExampleDescription
git checkout master@{yesterday}also 1 day ago, etc
git checkout master@{2}2nd prior value
git checkout master@{push}where master would push to
git checkout master^parent commit
git checkout master^22nd parent, eg, what it merged
git checkout master~55 parents back
git checkout master^0this commit; disambiguates from tags
git checkout v0.99.8^{tag}can be commit, tag, tree, object
git checkout v0.99.8^{}defaults to {tag}
git checkout ":/fix bug"searches commit messages

Other

ExampleDescription
HEAD:README...
0:README(0 to 3) ...

Ranges

Ranges

ExampleDescription
git log masterreachable parents from master
git log ^masterexclude reachable parents from master
git log master..fixreachable from fix but not master
git log master...fixreachable from fix and master, but not both
git log HEAD^@parents of HEAD
git log HEAD^!HEAD, then excluding parents's ancestors
git log HEAD^{:/fix}search previous HEADs matching criteria

Ranges illustration

A ─┬─ E ── F ── G   master
   │
   └─ B ── C ── D   fix
ExampleDescription
git log master..fixBCD
git log master...fixBCD and EFG

References

0 Comments for this cheatsheet. Write yours!