|
1 | 1 | --- |
2 | 2 | title: Git revisions |
3 | 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 `man gitrevisions`. |
4 | 9 | --- |
5 | 10 |
|
| 11 | +### Example usages |
| 12 | + |
| 13 | +```bash |
| 14 | +git log master...develop # inspect differences in branches |
| 15 | +git rebase -i HEAD~3 # rebase last 3 commits |
| 16 | +git reset --hard HEAD@{2} # undo last operation that changed HEAD |
| 17 | +git show ":/fix bug" # search commit with regex |
| 18 | +git checkout v2^{} # checkout the `v2` tag (not `v2` branch) |
| 19 | +``` |
| 20 | +The 3rd argument in each of these commands is a `gitrevision`. |
| 21 | + |
| 22 | +### Common git revisions |
| 23 | + |
| 24 | +| Reference | Description | |
| 25 | +| --- | --- | |
| 26 | +| `dae68e1` | sha1 | |
| 27 | +| `HEAD` | reference | |
| 28 | +| `v1.0.0` | tag | |
| 29 | +| --- | --- | |
| 30 | +| `master` | local branch | |
| 31 | +| `origin/master` | remote branch | |
| 32 | +| --- | --- | |
| 33 | +| `master~2` | 2 commits back from master | |
| 34 | +| --- | --- | |
| 35 | +| `master..fix` | reachable from *fix* but not *master* | |
| 36 | +| `master...fix` | reachable from *fix* and *master*, but not both | |
| 37 | + |
| 38 | +These are just the common ones, there's a lot more below! |
| 39 | + |
| 40 | +## Reference |
| 41 | + |
6 | 42 | ### Commits |
7 | 43 |
|
8 | 44 | | `dae68e1` | sha1 | |
9 | | -{:.shortcuts} |
10 | 45 |
|
11 | 46 | ### References |
12 | 47 |
|
13 | | -| `HEAD` | reference | |
14 | | -| `master` | branch | |
15 | | -| `v1.0.0` | tag | |
| 48 | +| `HEAD` | reference | |
| 49 | +| `master` | branch | |
| 50 | +| `v1.0.0` | tag | |
16 | 51 | | `origin/master` | aka, *refs/remotes/origin/master* | |
17 | | -| `heads/master` | aka, *refs/heads/master* | |
18 | | -{:.shortcuts} |
| 52 | +| `heads/master` | aka, *refs/heads/master* | |
19 | 53 |
|
20 | 54 | ### Searching back |
21 | 55 |
|
22 | | -| `master@{yesterday}` | also *1 day ago*, etc | |
23 | | -| `master@{2}` | 2nd prior value | |
24 | | -| `master@{push}` | where *master* would push to | |
25 | | -| `master^` | parent commit | |
26 | | -| `master^2` | 2nd parent, eg, what it merged | |
27 | | -| `master~5` | 5 parents back | |
28 | | -| `master^0` | this commit; disambiguates from tags | |
29 | | -| `v0.99.8^{tag}` | can be *commit*, *tag*, *tree*, *object* | |
30 | | -| `v0.99.8^{}` | defaults to *{tag}* | |
31 | | -| `:/fix bug` | searches commit messages | |
32 | | -{:.shortcuts} |
| 56 | +| `master@{yesterday}` | also *1 day ago*, etc | |
| 57 | +| `master@{2}` | 2nd prior value | |
| 58 | +| `master@{push}` | where *master* would push to | |
| 59 | +| `master^` | parent commit | |
| 60 | +| `master^2` | 2nd parent, eg, what it merged | |
| 61 | +| `master~5` | 5 parents back | |
| 62 | +| `master^0` | this commit; disambiguates from tags | |
| 63 | +| `v0.99.8^{tag}` | can be *commit*, *tag*, *tree*, *object* | |
| 64 | +| `v0.99.8^{}` | defaults to *{tag}* | |
| 65 | +| `:/fix bug` | searches commit messages | |
33 | 66 |
|
34 | 67 | ### Other |
35 | 68 |
|
36 | | -| `HEAD:README` | ... | |
37 | | -| `0:README` | (0 to 3) ... | |
38 | | -{:.shortcuts} |
| 69 | +| `HEAD:README` | ... | |
| 70 | +| `0:README` | (0 to 3) ... | |
39 | 71 |
|
40 | 72 | ## Ranges |
41 | 73 |
|
42 | | -| `master` | reachable parents from master | |
43 | | -| `^master` | exclude reachable parents from master | |
44 | | -| `master..fix` | reachable from *fix* but not *master* | |
| 74 | +### Ranges |
| 75 | + |
| 76 | +| `master` | reachable parents from master | |
| 77 | +| `^master` | exclude reachable parents from master | |
| 78 | +| `master..fix` | reachable from *fix* but not *master* | |
45 | 79 | | `master...fix` | reachable from *fix* and *master*, but not both | |
46 | | -| `HEAD^@` | parents of *HEAD* | |
47 | | -| `HEAD^!` | *HEAD*, then excluding parents's ancestors | |
48 | | -| `HEAD^{:/fix}` | search previous *HEAD*s matching criteria | |
49 | | -{:.shortcuts} |
| 80 | +| `HEAD^@` | parents of *HEAD* | |
| 81 | +| `HEAD^!` | *HEAD*, then excluding parents's ancestors | |
| 82 | +| `HEAD^{:/fix}` | search previous *HEAD*s matching criteria | |
50 | 83 |
|
51 | 84 | ### Ranges illustration |
52 | 85 |
|
53 | 86 | ```nohighlight |
54 | | -A -+- E - F - G master |
55 | | - '- B - C - D fix |
56 | | -
|
57 | | -master..fix = BCD |
58 | | -master...fix = BCD and EFG |
| 87 | +A ─┬─ E ── F ── G master |
| 88 | + │ |
| 89 | + └─ B ── C ── D fix |
59 | 90 | ``` |
| 91 | +{: .-box-chars.-setup} |
60 | 92 |
|
61 | | -## Example usages |
62 | | - |
63 | | -```sh |
64 | | -git log master...develop # inspect differences in branches |
65 | | -git rebase -i HEAD~3 # rebase last 3 commits |
66 | | -git reset --hard HEAD@{2} # undo last operation that changed HEAD |
67 | | -git show ":/fix bug" # search commit with regex |
68 | | -git checkout v2^{} # checkout the `v2` tag (not `v2` branch) |
69 | | -``` |
| 93 | +| `master..fix` | BCD | |
| 94 | +| `master...fix` | BCD and EFG | |
0 commit comments