8 A list of revision specifications you can use with `git log` and many other Git commands. Summarized from `gitrevisions(7)` man page.
13 | _`git log`_ `master...develop` | inspect differences in branches |
14 | _`git rebase -i`_ `HEAD~3` | rebase last 3 commits |
15 | _`git reset --hard`_ `HEAD@{2}` | undo last operation that changed HEAD |
16 | _`git checkout`_ `v2^{}` | checkout the `v2` tag (not `v2` branch) |
19 The 3rd argument in each of these commands is a `gitrevision`. These gitrevisions can be passed to many Git commands.
21 ### Common git revisions
23 | Reference | Description |
25 | _`git show`_ `dae68e1` | sha1 |
26 | _`git show`_ `HEAD` | reference |
27 | _`git show`_ `v1.0.0` | tag |
29 | _`git show`_ `master` | local branch |
30 | _`git show`_ `origin/master` | remote branch |
32 | _`git show`_ `master~2` | 2 commits back from master |
34 | _`git show`_ `master..fix` | reachable from *fix* but not *master* |
35 | _`git show`_ `master...fix` | reachable from *fix* and *master*, but not both |
38 These are just the common ones, there's a lot more below! (These work in many other commands, not just `git show`.)
44 | _`git checkout`_ `dae68e1` | sha1 |
49 | Example | Description |
51 | _`git checkout`_ `HEAD` | reference |
52 | _`git checkout`_ `master` | branch |
53 | _`git checkout`_ `v1.0.0` | tag |
55 | _`git checkout`_ `origin/master` | aka, *refs/remotes/origin/master* |
56 | _`git checkout`_ `heads/master` | aka, *refs/heads/master* |
61 | Example | Description |
63 | _`git checkout`_ `master@{yesterday}` | also *1 day ago*, etc |
64 | _`git checkout`_ `master@{2}` | 2nd prior value |
65 | _`git checkout`_ `master@{push}` | where *master* would push to |
67 | _`git checkout`_ `master^` | parent commit |
68 | _`git checkout`_ `master^2` | 2nd parent, eg, what it merged |
69 | _`git checkout`_ `master~5` | 5 parents back |
70 | _`git checkout`_ `master^0` | this commit; disambiguates from tags |
72 | _`git checkout`_ `v0.99.8^{tag}` | can be *commit*, *tag*, *tree*, *object* |
73 | _`git checkout`_ `v0.99.8^{}` | defaults to *{tag}* |
75 | _`git checkout`_ `":/fix bug"` | searches commit messages |
80 | `HEAD:README` | ... |
81 | `0:README` | (0 to 3) ... |
87 | _`git log`_ `master` | reachable parents from master |
88 | _`git log`_ `^master` | exclude reachable parents from master |
89 | _`git log`_ `master..fix` | reachable from *fix* but not *master* |
90 | _`git log`_ `master...fix` | reachable from *fix* and *master*, but not both |
91 | _`git log`_ `HEAD^@` | parents of *HEAD* |
92 | _`git log`_ `HEAD^!` | *HEAD*, then excluding parents's ancestors |
93 | _`git log`_ `HEAD^{:/fix}` | search previous *HEAD*s matching criteria |
96 ### Ranges illustration
99 A ─┬─ E ── F ── G master
103 {: .-box-chars.-setup}
105 | _`git log`_ `master..fix` | BCD |
106 | _`git log`_ `master...fix` | BCD and EFG |
111 * [Git Tools - Revision Selection](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html) _(git-scm.com)_
112 * [gitrevisions(7)](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html) _(kernel.org)_