cheatsheets/git-revisions.md

112 lines
5.0 KiB
Markdown
Raw Permalink Normal View History

2015-09-10 04:27:40 +00:00
---
title: Git revisions
2015-11-24 04:30:17 +00:00
category: Git
2017-10-10 16:11:14 +00:00
updated: 2017-10-11
description: ""
intro: |
2017-10-10 16:23:47 +00:00
A list of revision specifications you can use with `git log` and many other Git commands. Summarized from `gitrevisions(7)` man page.
2015-09-10 04:27:40 +00:00
---
2017-10-10 16:11:14 +00:00
### Example usages
2017-10-10 16:23:47 +00:00
| _`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 checkout`_ `v2^{}` | checkout the `v2` tag (not `v2` branch) |
{: .-mute-em}
The 3rd argument in each of these commands is a `gitrevision`. These gitrevisions can be passed to many Git commands.
2017-10-10 16:11:14 +00:00
### Common git revisions
2017-10-10 16:23:47 +00:00
| Reference | Description |
| --- | --- |
| _`git show`_ `dae68e1` | sha1 |
| _`git show`_ `HEAD` | reference |
| _`git show`_ `v1.0.0` | tag |
| --- | --- |
| _`git show`_ `master` | local branch |
| _`git show`_ `origin/master` | remote branch |
| --- | --- |
| _`git show`_ `master~2` | 2 commits back from master |
| --- | --- |
| _`git show`_ `master..fix` | reachable from *fix* but not *master* |
| _`git show`_ `master...fix` | reachable from *fix* and *master*, but not both |
{: .-mute-em}
These are just the common ones, there's a lot more below! (These work in many other commands, not just `git show`.)
2017-10-10 16:11:14 +00:00
## Reference
2015-09-10 04:32:35 +00:00
### Commits
2017-10-10 16:23:47 +00:00
| _`git checkout`_ `dae68e1` | sha1 |
{: .-mute-em}
2015-09-10 04:32:35 +00:00
### References
2017-10-10 16:23:47 +00:00
| Example | Description |
| --- | --- |
| _`git checkout`_ `HEAD` | reference |
| _`git checkout`_ `master` | branch |
| _`git checkout`_ `v1.0.0` | tag |
| --- | --- |
| _`git checkout`_ `origin/master` | aka, *refs/remotes/origin/master* |
| _`git checkout`_ `heads/master` | aka, *refs/heads/master* |
{: .-mute-em}
2015-09-10 04:32:35 +00:00
### Searching back
2017-10-10 16:23:47 +00:00
| Example | Description |
| --- | --- |
| _`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^2` | 2nd parent, eg, what it merged |
| _`git checkout`_ `master~5` | 5 parents back |
| _`git checkout`_ `master^0` | this 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 |
{: .-mute-em}
2015-09-10 04:32:35 +00:00
### Other
2017-10-10 16:11:14 +00:00
| `HEAD:README` | ... |
| `0:README` | (0 to 3) ... |
2015-09-10 04:32:35 +00:00
## Ranges
2017-10-10 16:11:14 +00:00
### Ranges
2017-10-10 16:23:47 +00:00
| _`git log`_ `master` | reachable parents from master |
| _`git log`_ `^master` | exclude reachable parents from master |
| _`git log`_ `master..fix` | reachable from *fix* but not *master* |
| _`git log`_ `master...fix` | reachable 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 *HEAD*s matching criteria |
{: .-mute-em}
2015-09-10 04:27:40 +00:00
### Ranges illustration
2015-09-10 04:36:00 +00:00
```nohighlight
2017-10-10 16:11:14 +00:00
A ─┬─ E ── F ── G master
└─ B ── C ── D fix
2015-09-10 04:27:40 +00:00
```
2017-10-10 16:11:14 +00:00
{: .-box-chars.-setup}
2015-09-10 04:41:25 +00:00
2017-10-10 16:23:47 +00:00
| _`git log`_ `master..fix` | BCD |
| _`git log`_ `master...fix` | BCD and EFG |
{: .-mute-em}
## References
* [Git Tools - Revision Selection](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html) _(git-scm.com)_
* [gitrevisions(7)](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html) _(kernel.org)_