OSDN Git Service

Regular updates
[twpd/master.git] / git-revisions.md
1 ---
2 title: Git revisions
3 category: Git
4 layout: 2017/sheet
5 updated: 2017-10-11
6 description: ""
7 intro: |
8   A list of revision specifications you can use with `git log` and many other Git commands. Summarized from `gitrevisions(7)` man page.
9 ---
10
11 ### Example usages
12
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) |
17 {: .-mute-em}
18
19 The 3rd argument in each of these commands is a `gitrevision`. These gitrevisions can be passed to many Git commands.
20
21 ### Common git revisions
22
23 | Reference                    | Description                                     |
24 | ---                          | ---                                             |
25 | _`git show`_ `dae68e1`       | sha1                                            |
26 | _`git show`_ `HEAD`          | reference                                       |
27 | _`git show`_ `v1.0.0`        | tag                                             |
28 | ---                          | ---                                             |
29 | _`git show`_ `master`        | local branch                                    |
30 | _`git show`_ `origin/master` | remote branch                                   |
31 | ---                          | ---                                             |
32 | _`git show`_ `master~2`      | 2 commits back from master                      |
33 | ---                          | ---                                             |
34 | _`git show`_ `master..fix`   | reachable from *fix* but not *master*           |
35 | _`git show`_ `master...fix`  | reachable from *fix* and *master*, but not both |
36 {: .-mute-em}
37
38 These are just the common ones, there's a lot more below! (These work in many other commands, not just `git show`.)
39
40 ## Reference
41
42 ### Commits
43
44 | _`git checkout`_ `dae68e1` | sha1 |
45 {: .-mute-em}
46
47 ### References
48
49 | Example                          | Description                       |
50 | ---                              | ---                               |
51 | _`git checkout`_ `HEAD`          | reference                         |
52 | _`git checkout`_ `master`        | branch                            |
53 | _`git checkout`_ `v1.0.0`        | tag                               |
54 | ---                              | ---                               |
55 | _`git checkout`_ `origin/master` | aka, *refs/remotes/origin/master* |
56 | _`git checkout`_ `heads/master`  | aka, *refs/heads/master*          |
57 {: .-mute-em}
58
59 ### Searching back
60
61 | Example                               | Description                              |
62 | ---                                   | ---                                      |
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             |
66 | ---                                   | ---                                      |
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     |
71 | ---                                   | ---                                      |
72 | _`git checkout`_ `v0.99.8^{tag}`      | can be *commit*, *tag*, *tree*, *object* |
73 | _`git checkout`_ `v0.99.8^{}`         | defaults to *{tag}*                      |
74 | ---                                   | ---                                      |
75 | _`git checkout`_ `":/fix bug"`        | searches commit messages                 |
76 {: .-mute-em}
77
78 ### Other
79
80 | `HEAD:README` | ...          |
81 | `0:README`    | (0 to 3) ... |
82
83 ## Ranges
84
85 ### Ranges
86
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       |
94 {: .-mute-em}
95
96 ### Ranges illustration
97
98 ```nohighlight
99 A ─┬─ E ── F ── G   master
100    │
101    └─ B ── C ── D   fix
102 ```
103 {: .-box-chars.-setup}
104
105 | _`git log`_ `master..fix`  | BCD         |
106 | _`git log`_ `master...fix` | BCD and EFG |
107 {: .-mute-em}
108
109 ## References
110
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)_