git-revisions: update

This commit is contained in:
Rico Sta. Cruz 2017-10-11 00:11:14 +08:00
parent 5b6956a33c
commit aa4eb500b7
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 82 additions and 57 deletions

View File

@ -1,12 +1,47 @@
--- ---
title: Git revisions title: Git revisions
category: Git category: Git
layout: 2017/sheet
updated: 2017-10-11
description: ""
intro: |
A list of revision specifications you can use with `git log` and many other Git commands. Summarized from `man gitrevisions`.
--- ---
### Example usages
```bash
git log master...develop # inspect differences in branches
git rebase -i HEAD~3 # rebase last 3 commits
git reset --hard HEAD@{2} # undo last operation that changed HEAD
git show ":/fix bug" # search commit with regex
git checkout v2^{} # checkout the `v2` tag (not `v2` branch)
```
The 3rd argument in each of these commands is a `gitrevision`.
### Common git revisions
| Reference | Description |
| --- | --- |
| `dae68e1` | sha1 |
| `HEAD` | reference |
| `v1.0.0` | tag |
| --- | --- |
| `master` | local branch |
| `origin/master` | remote branch |
| --- | --- |
| `master~2` | 2 commits back from master |
| --- | --- |
| `master..fix` | reachable from *fix* but not *master* |
| `master...fix` | reachable from *fix* and *master*, but not both |
These are just the common ones, there's a lot more below!
## Reference
### Commits ### Commits
| `dae68e1` | sha1 | | `dae68e1` | sha1 |
{:.shortcuts}
### References ### References
@ -15,7 +50,6 @@ category: Git
| `v1.0.0` | tag | | `v1.0.0` | tag |
| `origin/master` | aka, *refs/remotes/origin/master* | | `origin/master` | aka, *refs/remotes/origin/master* |
| `heads/master` | aka, *refs/heads/master* | | `heads/master` | aka, *refs/heads/master* |
{:.shortcuts}
### Searching back ### Searching back
@ -29,16 +63,16 @@ category: Git
| `v0.99.8^{tag}` | can be *commit*, *tag*, *tree*, *object* | | `v0.99.8^{tag}` | can be *commit*, *tag*, *tree*, *object* |
| `v0.99.8^{}` | defaults to *{tag}* | | `v0.99.8^{}` | defaults to *{tag}* |
| `:/fix bug` | searches commit messages | | `:/fix bug` | searches commit messages |
{:.shortcuts}
### Other ### Other
| `HEAD:README` | ... | | `HEAD:README` | ... |
| `0:README` | (0 to 3) ... | | `0:README` | (0 to 3) ... |
{:.shortcuts}
## Ranges ## Ranges
### Ranges
| `master` | reachable parents from master | | `master` | reachable parents from master |
| `^master` | exclude reachable parents from master | | `^master` | exclude reachable parents from master |
| `master..fix` | reachable from *fix* but not *master* | | `master..fix` | reachable from *fix* but not *master* |
@ -46,24 +80,15 @@ category: Git
| `HEAD^@` | parents of *HEAD* | | `HEAD^@` | parents of *HEAD* |
| `HEAD^!` | *HEAD*, then excluding parents's ancestors | | `HEAD^!` | *HEAD*, then excluding parents's ancestors |
| `HEAD^{:/fix}` | search previous *HEAD*s matching criteria | | `HEAD^{:/fix}` | search previous *HEAD*s matching criteria |
{:.shortcuts}
### Ranges illustration ### Ranges illustration
```nohighlight ```nohighlight
A -+- E - F - G master A ─┬─ E ── F ── G master
'- B - C - D fix
└─ B ── C ── D fix
master..fix = BCD
master...fix = BCD and EFG
``` ```
{: .-box-chars.-setup}
## Example usages | `master..fix` | BCD |
| `master...fix` | BCD and EFG |
```sh
git log master...develop # inspect differences in branches
git rebase -i HEAD~3 # rebase last 3 commits
git reset --hard HEAD@{2} # undo last operation that changed HEAD
git show ":/fix bug" # search commit with regex
git checkout v2^{} # checkout the `v2` tag (not `v2` branch)
```