|
1 |
| -##Git Treeishes |
| 1 | +## Git Treeishes ## |
| 2 | + |
| 3 | +There are a number of ways to refer to a particular commit or tree other |
| 4 | +than spelling out the entire 40-character sha. |
| 5 | + |
| 6 | +### Partial Sha ### |
| 7 | + |
| 8 | +If your commit sha is '<code>980e3ccdaac54a0d4de358f3fe5d718027d96aae</code>', git will |
| 9 | +recognize any of the following identically: |
| 10 | + |
| 11 | + 980e3ccdaac54a0d4de358f3fe5d718027d96aae |
| 12 | + 980e3ccdaac54a0d4 |
| 13 | + 980e3cc |
| 14 | + |
| 15 | +As long as the partial sha is unique - it can't be confused with another |
| 16 | +(which is incredibly unlikely if you use at least 5 characters), git will |
| 17 | +expand a partial sha for you. |
| 18 | + |
| 19 | +### Branch, Remote or Tag Name ### |
| 20 | + |
| 21 | +You can always use a branch, remote or tag name instead of a sha, since they |
| 22 | +are simply pointers anyhow. If your master branch is on the 980e3 commit and |
| 23 | +you've pushed it to origin and have tagged it 'v1.0', then all of the following |
| 24 | +are equivalent: |
| 25 | + |
| 26 | + 980e3ccdaac54a0d4de358f3fe5d718027d96aae |
| 27 | + origin/master |
| 28 | + refs/remotes/origin/master |
| 29 | + master |
| 30 | + refs/heads/master |
| 31 | + v1.0 |
| 32 | + refs/tags/v1.0 |
| 33 | + |
| 34 | +Which means the following will give you identical output: |
| 35 | + |
| 36 | + $ git log master |
| 37 | + |
| 38 | + $ git log refs/tags/v1.0 |
| 39 | + |
| 40 | +### Date Spec ### |
| 41 | + |
| 42 | +The Ref Log that git keeps will allow you to do some relative stuff locally, |
| 43 | +such as: |
| 44 | + |
| 45 | + master@{yesterday} |
| 46 | + |
| 47 | + master@{1 month ago} |
| 48 | + |
| 49 | +Which is shorthand for 'where the master branch head was yesterday', etc. Note |
| 50 | +that this format can result in different shas on different computers, even if |
| 51 | +the master branch is currently pointing to the same place. |
| 52 | + |
| 53 | +### Ordinal Spec ### |
| 54 | + |
| 55 | +This format will give you the Nth previous value of a particular reference. |
| 56 | +For example: |
| 57 | + |
| 58 | + master@{5} |
| 59 | + |
| 60 | +will give you the 5th prior value of the master head ref. |
| 61 | + |
| 62 | +### Carrot Parent ### |
| 63 | + |
| 64 | +This will give you the Nth parent of a particular commit. This format is only |
| 65 | +useful on merge commits - commit objects that have more than one direct parent. |
| 66 | + |
| 67 | + master^2 |
| 68 | + |
| 69 | + |
| 70 | +### Tilde Spec ### |
| 71 | + |
| 72 | +The tilde spec will give you the Nth grandparent of a commit object. For example, |
| 73 | + |
| 74 | + master~2 |
| 75 | + |
| 76 | +will give us the first parent of the first parent of the commit that master |
| 77 | +points to. It is equivalent to: |
| 78 | + |
| 79 | + master^^ |
| 80 | + |
| 81 | +You can keep doing this, too. The following specs will point to the same commit: |
| 82 | + |
| 83 | + master^^^^^^ |
| 84 | + master~3^~2 |
| 85 | + master~6 |
| 86 | + |
| 87 | +### Tree Pointer ### |
| 88 | + |
| 89 | +This disambiguates a commit from the tree that it points to. If you want the |
| 90 | +sha that a commit points to, you can add the '^{tree}' spec to the end of it. |
| 91 | + |
| 92 | + master^{tree} |
| 93 | + |
| 94 | +### Blob Spec ### |
| 95 | + |
| 96 | +If you want the sha of a particular blob, you can add the blob path at the |
| 97 | +end of the treeish, like so: |
| 98 | + |
| 99 | + master:/path/to/file |
| 100 | + |
| 101 | +### Range ### |
| 102 | + |
| 103 | +Finally, you can specify a range of commits with the range spec. This will |
| 104 | +give you all the commits between 7b593b5 and 51bea1 (where 51bea1 is most recent), |
| 105 | +excluding 7b593b5 but including 51bea1: |
| 106 | + |
| 107 | + 7b593b5..51bea1 |
| 108 | + |
| 109 | +This will include every commit *since* 7b593b: |
| 110 | + |
| 111 | + 7b593b.. |
| 112 | + |
| 113 | + |
0 commit comments