1GITREVISIONS(7) Git Manual GITREVISIONS(7)
2
3
4
6 gitrevisions - specifying revisions and ranges for Git
7
9 gitrevisions
10
12 Many Git commands take revision parameters as arguments. Depending on
13 the command, they denote a specific commit or, for commands which walk
14 the revision graph (such as git-log(1)), all commits which can be
15 reached from that commit. In the latter case one can also specify a
16 range of revisions explicitly.
17
18 In addition, some Git commands (such as git-show(1)) also take revision
19 parameters which denote other objects than commits, e.g. blobs
20 ("files") or trees ("directories of files").
21
23 A revision parameter <rev> typically, but not necessarily, names a
24 commit object. It uses what is called an extended SHA-1 syntax. Here
25 are various ways to spell object names. The ones listed near the end of
26 this list name trees and blobs contained in a commit.
27
28 <sha1>, e.g. dae86e1950b1277e545cee180551750029cfe735, dae86e
29 The full SHA-1 object name (40-byte hexadecimal string), or a
30 leading substring that is unique within the repository. E.g.
31 dae86e1950b1277e545cee180551750029cfe735 and dae86e both name the
32 same commit object if there is no other object in your repository
33 whose object name starts with dae86e.
34
35 <describeOutput>, e.g. v1.7.4.2-679-g3bee7fb
36 Output from git describe; i.e. a closest tag, optionally followed
37 by a dash and a number of commits, followed by a dash, a g, and an
38 abbreviated object name.
39
40 <refname>, e.g. master, heads/master, refs/heads/master
41 A symbolic ref name. E.g. master typically means the commit object
42 referenced by refs/heads/master. If you happen to have both
43 heads/master and tags/master, you can explicitly say heads/master
44 to tell Git which one you mean. When ambiguous, a <refname> is
45 disambiguated by taking the first match in the following rules:
46
47 1. If $GIT_DIR/<refname> exists, that is what you mean (this is
48 usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD
49 and CHERRY_PICK_HEAD);
50
51 2. otherwise, refs/<refname> if it exists;
52
53 3. otherwise, refs/tags/<refname> if it exists;
54
55 4. otherwise, refs/heads/<refname> if it exists;
56
57 5. otherwise, refs/remotes/<refname> if it exists;
58
59 6. otherwise, refs/remotes/<refname>/HEAD if it exists.
60
61 HEAD names the commit on which you based the changes in the
62 working tree. FETCH_HEAD records the branch which you fetched
63 from a remote repository with your last git fetch invocation.
64 ORIG_HEAD is created by commands that move your HEAD in a
65 drastic way, to record the position of the HEAD before their
66 operation, so that you can easily change the tip of the branch
67 back to the state before you ran them. MERGE_HEAD records the
68 commit(s) which you are merging into your branch when you run
69 git merge. CHERRY_PICK_HEAD records the commit which you are
70 cherry-picking when you run git cherry-pick.
71
72 Note that any of the refs/* cases above may come either from
73 the $GIT_DIR/refs directory or from the $GIT_DIR/packed-refs
74 file. While the ref name encoding is unspecified, UTF-8 is
75 preferred as some output processing may assume ref names in
76 UTF-8.
77
78 <refname>@{<date>}, e.g. master@{yesterday}, HEAD@{5 minutes ago}
79 A ref followed by the suffix @ with a date specification enclosed
80 in a brace pair (e.g. {yesterday}, {1 month 2 weeks 3 days 1 hour
81 1 second ago} or {1979-02-26 18:30:00}) specifies the value of the
82 ref at a prior point in time. This suffix may only be used
83 immediately following a ref name and the ref must have an existing
84 log ($GIT_DIR/logs/<ref>). Note that this looks up the state of
85 your local ref at a given time; e.g., what was in your local master
86 branch last week. If you want to look at commits made during
87 certain times, see --since and --until.
88
89 <refname>@{<n>}, e.g. master@{1}
90 A ref followed by the suffix @ with an ordinal specification
91 enclosed in a brace pair (e.g. {1}, {15}) specifies the n-th prior
92 value of that ref. For example master@{1} is the immediate prior
93 value of master while master@{5} is the 5th prior value of master.
94 This suffix may only be used immediately following a ref name and
95 the ref must have an existing log ($GIT_DIR/logs/<refname>).
96
97 @{<n>}, e.g. @{1}
98 You can use the @ construct with an empty ref part to get at a
99 reflog entry of the current branch. For example, if you are on
100 branch blabla then @{1} means the same as blabla@{1}.
101
102 @{-<n>}, e.g. @{-1}
103 The construct @{-<n>} means the <n>th branch checked out before the
104 current one.
105
106 <branchname>@{upstream}, e.g. master@{upstream}, @{u}
107 The suffix @{upstream} to a branchname (short form
108 <branchname>@{u}) refers to the branch that the branch specified by
109 branchname is set to build on top of. A missing branchname defaults
110 to the current one.
111
112 <rev>^, e.g. HEAD^, v1.5.1^0
113 A suffix ^ to a revision parameter means the first parent of that
114 commit object. ^<n> means the <n>th parent (i.e. <rev>^ is
115 equivalent to <rev>^1). As a special rule, <rev>^0 means the commit
116 itself and is used when <rev> is the object name of a tag object
117 that refers to a commit object.
118
119 <rev>~<n>, e.g. master~3
120 A suffix ~<n> to a revision parameter means the commit object that
121 is the <n>th generation ancestor of the named commit object,
122 following only the first parents. I.e. <rev>~3 is equivalent to
123 <rev>^^^ which is equivalent to <rev>^1^1^1. See below for an
124 illustration of the usage of this form.
125
126 <rev>^{<type>}, e.g. v0.99.8^{commit}
127 A suffix ^ followed by an object type name enclosed in brace pair
128 means the object could be a tag, and dereference the tag
129 recursively until an object of that type is found or the object
130 cannot be dereferenced anymore (in which case, barf). <rev>^0 is a
131 short-hand for <rev>^{commit}.
132
133 rev^{object} can be used to make sure rev names an object that
134 exists, without requiring rev to be a tag, and without
135 dereferencing rev; because a tag is already an object, it does not
136 have to be dereferenced even once to get to an object.
137
138 <rev>^{}, e.g. v0.99.8^{}
139 A suffix ^ followed by an empty brace pair means the object could
140 be a tag, and dereference the tag recursively until a non-tag
141 object is found.
142
143 <rev>^{/<text>}, e.g. HEAD^{/fix nasty bug}
144 A suffix ^ to a revision parameter, followed by a brace pair that
145 contains a text led by a slash, is the same as the :/fix nasty bug
146 syntax below except that it returns the youngest matching commit
147 which is reachable from the <rev> before ^.
148
149 :/<text>, e.g. :/fix nasty bug
150 A colon, followed by a slash, followed by a text, names a commit
151 whose commit message matches the specified regular expression. This
152 name returns the youngest matching commit which is reachable from
153 any ref. If the commit message starts with a ! you have to repeat
154 that; the special sequence :/!, followed by something else than !,
155 is reserved for now. The regular expression can match any part of
156 the commit message. To match messages starting with a string, one
157 can use e.g. :/^foo.
158
159 <rev>:<path>, e.g. HEAD:README, :README, master:./README
160 A suffix : followed by a path names the blob or tree at the given
161 path in the tree-ish object named by the part before the colon.
162 :path (with an empty part before the colon) is a special case of
163 the syntax described next: content recorded in the index at the
164 given path. A path starting with ./ or ../ is relative to the
165 current working directory. The given path will be converted to be
166 relative to the working tree’s root directory. This is most useful
167 to address a blob or tree from a commit or tree that has the same
168 tree structure as the working tree.
169
170 :<n>:<path>, e.g. :0:README, :README
171 A colon, optionally followed by a stage number (0 to 3) and a
172 colon, followed by a path, names a blob object in the index at the
173 given path. A missing stage number (and the colon that follows it)
174 names a stage 0 entry. During a merge, stage 1 is the common
175 ancestor, stage 2 is the target branch’s version (typically the
176 current branch), and stage 3 is the version from the branch which
177 is being merged.
178
179 Here is an illustration, by Jon Loeliger. Both commit nodes B and C are
180 parents of commit node A. Parent commits are ordered left-to-right.
181
182 G H I J
183 \ / \ /
184 D E F
185 \ | / \
186 \ | / |
187 \|/ |
188 B C
189 \ /
190 \ /
191 A
192
193 A = = A^0
194 B = A^ = A^1 = A~1
195 C = A^2 = A^2
196 D = A^^ = A^1^1 = A~2
197 E = B^2 = A^^2
198 F = B^3 = A^^3
199 G = A^^^ = A^1^1^1 = A~3
200 H = D^2 = B^^2 = A^^^2 = A~2^2
201 I = F^ = B^3^ = A^^3^
202 J = F^2 = B^3^2 = A^^3^2
203
205 History traversing commands such as git log operate on a set of
206 commits, not just a single commit. To these commands, specifying a
207 single revision with the notation described in the previous section
208 means the set of commits reachable from that commit, following the
209 commit ancestry chain.
210
211 To exclude commits reachable from a commit, a prefix ^ notation is
212 used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones
213 reachable from r1.
214
215 This set operation appears so often that there is a shorthand for it.
216 When you have two commits r1 and r2 (named according to the syntax
217 explained in SPECIFYING REVISIONS above), you can ask for commits that
218 are reachable from r2 excluding those that are reachable from r1 by ^r1
219 r2 and it can be written as r1..r2.
220
221 A similar notation r1...r2 is called symmetric difference of r1 and r2
222 and is defined as r1 r2 --not $(git merge-base --all r1 r2). It is the
223 set of commits that are reachable from either one of r1 or r2 but not
224 from both.
225
226 In these two shorthands, you can omit one end and let it default to
227 HEAD. For example, origin.. is a shorthand for origin..HEAD and asks
228 "What did I do since I forked from the origin branch?" Similarly,
229 ..origin is a shorthand for HEAD..origin and asks "What did the origin
230 do since I forked from them?" Note that .. would mean HEAD..HEAD which
231 is an empty range that is both reachable and unreachable from HEAD.
232
233 Two other shorthands for naming a set that is formed by a commit and
234 its parent commits exist. The r1^@ notation means all parents of r1.
235 r1^! includes commit r1 but excludes all of its parents.
236
237 To summarize:
238
239 <rev>
240 Include commits that are reachable from (i.e. ancestors of) <rev>.
241
242 ^<rev>
243 Exclude commits that are reachable from (i.e. ancestors of) <rev>.
244
245 <rev1>..<rev2>
246 Include commits that are reachable from <rev2> but exclude those
247 that are reachable from <rev1>. When either <rev1> or <rev2> is
248 omitted, it defaults to HEAD.
249
250 <rev1>...<rev2>
251 Include commits that are reachable from either <rev1> or <rev2> but
252 exclude those that are reachable from both. When either <rev1> or
253 <rev2> is omitted, it defaults to HEAD.
254
255 <rev>^@, e.g. HEAD^@
256 A suffix ^ followed by an at sign is the same as listing all
257 parents of <rev> (meaning, include anything reachable from its
258 parents, but not the commit itself).
259
260 <rev>^!, e.g. HEAD^!
261 A suffix ^ followed by an exclamation mark is the same as giving
262 commit <rev> and then all its parents prefixed with ^ to exclude
263 them (and their ancestors).
264
265 Here are a handful of examples:
266
267 D G H D
268 D F G H I J D F
269 ^G D H D
270 ^D B E I J F B
271 B..C C
272 B...C G H D E B C
273 ^D B C E I J F B C
274 C I J F C
275 C^@ I J F
276 C^! C
277 F^! D G H D F
278
280 git-rev-parse(1)
281
283 Part of the git(1) suite
284
285
286
287Git 1.8.3.1 11/19/2018 GITREVISIONS(7)