1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="gitrevisions(7)">
\r
5 <title>gitrevisions(7)</title>
\r
7 <primary>gitrevisions(7)</primary>
\r
9 <simplesect id="gitrevisions(7)__name">
\r
11 <simpara>gitrevisions - specifying revisions and ranges for git</simpara>
\r
13 <simplesect id="gitrevisions(7)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
15 <simpara>gitrevisions</simpara>
\r
17 <simplesect id="gitrevisions(7)__description">
\r
18 <title>DESCRIPTION</title>
\r
19 <simpara>Many Git commands take revision parameters as arguments. Depending on
\r
20 the command, they denote a specific commit or, for commands which
\r
21 walk the revision graph (such as <xref linkend="git-log(1)" />), all commits which can
\r
22 be reached from that commit. In the latter case one can also specify a
\r
23 range of revisions explicitly.</simpara>
\r
24 <simpara>In addition, some Git commands (such as <xref linkend="git-show(1)" />) also take
\r
25 revision parameters which denote other objects than commits, e.g. blobs
\r
26 ("files") or trees ("directories of files").</simpara>
\r
28 <simplesect id="gitrevisions(7)__specifying_revisions">
\r
29 <title>SPECIFYING REVISIONS</title>
\r
30 <simpara>A revision parameter <emphasis><rev></emphasis> typically, but not necessarily, names a
\r
31 commit object. It uses what is called an <emphasis>extended SHA1</emphasis>
\r
32 syntax. Here are various ways to spell object names. The
\r
33 ones listed near the end of this list name trees and
\r
34 blobs contained in a commit.</simpara>
\r
38 <emphasis><sha1></emphasis>, e.g. <emphasis>dae86e1950b1277e545cee180551750029cfe735</emphasis>, <emphasis>dae86e</emphasis>
\r
42 The full SHA1 object name (40-byte hexadecimal string), or
\r
43 a leading substring that is unique within the repository.
\r
44 E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both
\r
45 name the same commit object if there is no other object in
\r
46 your repository whose object name starts with dae86e.
\r
52 <emphasis><describeOutput></emphasis>, e.g. <emphasis>v1.7.4.2-679-g3bee7fb</emphasis>
\r
56 Output from <emphasis>git describe</emphasis>; i.e. a closest tag, optionally
\r
57 followed by a dash and a number of commits, followed by a dash, a
\r
58 <emphasis>g</emphasis>, and an abbreviated object name.
\r
64 <emphasis><refname></emphasis>, e.g. <emphasis>master</emphasis>, <emphasis>heads/master</emphasis>, <emphasis>refs/heads/master</emphasis>
\r
68 A symbolic ref name. E.g. <emphasis>master</emphasis> typically means the commit
\r
69 object referenced by <emphasis>refs/heads/master</emphasis>. If you
\r
70 happen to have both <emphasis>heads/master</emphasis> and <emphasis>tags/master</emphasis>, you can
\r
71 explicitly say <emphasis>heads/master</emphasis> to tell git which one you mean.
\r
72 When ambiguous, a <emphasis><refname></emphasis> is disambiguated by taking the
\r
73 first match in the following rules:
\r
75 <orderedlist numeration="arabic">
\r
78 If <emphasis>$GIT_DIR/<refname></emphasis> exists, that is what you mean (this is usually
\r
79 useful only for <emphasis>HEAD</emphasis>, <emphasis>FETCH_HEAD</emphasis>, <emphasis>ORIG_HEAD</emphasis>, <emphasis>MERGE_HEAD</emphasis>
\r
80 and <emphasis>CHERRY_PICK_HEAD</emphasis>);
\r
85 otherwise, <emphasis>refs/<refname></emphasis> if it exists;
\r
90 otherwise, <emphasis>refs/tags/<refname></emphasis> if it exists;
\r
95 otherwise, <emphasis>refs/heads/<refname></emphasis> if it exists;
\r
100 otherwise, <emphasis>refs/remotes/<refname></emphasis> if it exists;
\r
105 otherwise, <emphasis>refs/remotes/<refname>/HEAD</emphasis> if it exists.
\r
107 <simpara><emphasis>HEAD</emphasis> names the commit on which you based the changes in the working tree.
\r
108 <emphasis>FETCH_HEAD</emphasis> records the branch which you fetched from a remote repository
\r
109 with your last <emphasis>git fetch</emphasis> invocation.
\r
110 <emphasis>ORIG_HEAD</emphasis> is created by commands that move your <emphasis>HEAD</emphasis> in a drastic
\r
111 way, to record the position of the <emphasis>HEAD</emphasis> before their operation, so that
\r
112 you can easily change the tip of the branch back to the state before you ran
\r
114 <emphasis>MERGE_HEAD</emphasis> records the commit(s) which you are merging into your branch
\r
115 when you run <emphasis>git merge</emphasis>.
\r
116 <emphasis>CHERRY_PICK_HEAD</emphasis> records the commit which you are cherry-picking
\r
117 when you run <emphasis>git cherry-pick</emphasis>.</simpara>
\r
118 <simpara>Note that any of the <emphasis>refs/*</emphasis> cases above may come either from
\r
119 the <emphasis>$GIT_DIR/refs</emphasis> directory or from the <emphasis>$GIT_DIR/packed-refs</emphasis> file.
\r
120 While the ref name encoding is unspecified, UTF-8 is prefered as
\r
121 some output processing may assume ref names in UTF-8.</simpara>
\r
128 <emphasis><refname>@{<date>}</emphasis>, e.g. <emphasis>master@{yesterday}</emphasis>, <emphasis>HEAD@{5 minutes ago}</emphasis>
\r
132 A ref followed by the suffix <emphasis>@</emphasis> with a date specification
\r
133 enclosed in a brace
\r
134 pair (e.g. <emphasis>{yesterday}</emphasis>, <emphasis>{1 month 2 weeks 3 days 1 hour 1
\r
135 second ago}</emphasis> or <emphasis>{1979-02-26 18:30:00}</emphasis>) specifies the value
\r
136 of the ref at a prior point in time. This suffix may only be
\r
137 used immediately following a ref name and the ref must have an
\r
138 existing log (<emphasis>$GIT_DIR/logs/<ref></emphasis>). Note that this looks up the state
\r
139 of your <emphasis role="strong">local</emphasis> ref at a given time; e.g., what was in your local
\r
140 <emphasis>master</emphasis> branch last week. If you want to look at commits made during
\r
141 certain times, see <emphasis>--since</emphasis> and <emphasis>--until</emphasis>.
\r
147 <emphasis><refname>@{<n>}</emphasis>, e.g. <emphasis>master@{1}</emphasis>
\r
151 A ref followed by the suffix <emphasis>@</emphasis> with an ordinal specification
\r
152 enclosed in a brace pair (e.g. <emphasis>{1}</emphasis>, <emphasis>{15}</emphasis>) specifies
\r
153 the n-th prior value of that ref. For example <emphasis>master@{1}</emphasis>
\r
154 is the immediate prior value of <emphasis>master</emphasis> while <emphasis>master@{5}</emphasis>
\r
155 is the 5th prior value of <emphasis>master</emphasis>. This suffix may only be used
\r
156 immediately following a ref name and the ref must have an existing
\r
157 log (<emphasis>$GIT_DIR/logs/<refname></emphasis>).
\r
163 <emphasis>@{<n>}</emphasis>, e.g. <emphasis>@{1}</emphasis>
\r
167 You can use the <emphasis>@</emphasis> construct with an empty ref part to get at a
\r
168 reflog entry of the current branch. For example, if you are on
\r
169 branch <emphasis>blabla</emphasis> then <emphasis>@{1}</emphasis> means the same as <emphasis>blabla@{1}</emphasis>.
\r
175 <emphasis>@{-<n>}</emphasis>, e.g. <emphasis>@{-1}</emphasis>
\r
179 The construct <emphasis>@{-<n>}</emphasis> means the <n>th branch checked out
\r
180 before the current one.
\r
186 <emphasis><refname>@{upstream}</emphasis>, e.g. <emphasis>master@{upstream}</emphasis>, <emphasis>@{u}</emphasis>
\r
190 The suffix <emphasis>@{upstream}</emphasis> to a ref (short form <emphasis><refname>@{u}</emphasis>) refers to
\r
191 the branch the ref is set to build on top of. A missing ref defaults
\r
192 to the current branch.
\r
198 <emphasis><rev>^</emphasis>, e.g. <emphasis>HEAD^, v1.5.1^0</emphasis>
\r
202 A suffix <emphasis>^</emphasis> to a revision parameter means the first parent of
\r
203 that commit object. <emphasis>^<n></emphasis> means the <n>th parent (i.e.
\r
204 <emphasis><rev>^</emphasis>
\r
205 is equivalent to <emphasis><rev>^1</emphasis>). As a special rule,
\r
206 <emphasis><rev>^0</emphasis> means the commit itself and is used when <emphasis><rev></emphasis> is the
\r
207 object name of a tag object that refers to a commit object.
\r
213 <emphasis><rev>~<n></emphasis>, e.g. <emphasis>master~3</emphasis>
\r
217 A suffix <emphasis>~<n></emphasis> to a revision parameter means the commit
\r
218 object that is the <n>th generation ancestor of the named
\r
219 commit object, following only the first parents. I.e. <emphasis><rev>~3</emphasis> is
\r
220 equivalent to <emphasis><rev>^^^</emphasis> which is equivalent to
\r
221 <emphasis><rev>^1^1^1</emphasis>. See below for an illustration of
\r
222 the usage of this form.
\r
228 <emphasis><rev>^{<type>}</emphasis>, e.g. <emphasis>v0.99.8^{commit}</emphasis>
\r
232 A suffix <emphasis>^</emphasis> followed by an object type name enclosed in
\r
233 brace pair means the object
\r
234 could be a tag, and dereference the tag recursively until an
\r
235 object of that type is found or the object cannot be
\r
236 dereferenced anymore (in which case, barf). <emphasis><rev>^0</emphasis>
\r
237 is a short-hand for <emphasis><rev>^{commit}</emphasis>.
\r
243 <emphasis><rev>^{}</emphasis>, e.g. <emphasis>v0.99.8^{}</emphasis>
\r
247 A suffix <emphasis>^</emphasis> followed by an empty brace pair
\r
248 means the object could be a tag,
\r
249 and dereference the tag recursively until a non-tag object is
\r
256 <emphasis><rev>^{/<text>}</emphasis>, e.g. <emphasis>HEAD^{/fix nasty bug}</emphasis>
\r
260 A suffix <emphasis>^</emphasis> to a revision parameter, followed by a brace
\r
261 pair that contains a text led by a slash,
\r
262 is the same as the <emphasis>:/fix nasty bug</emphasis> syntax below except that
\r
263 it returns the youngest matching commit which is reachable from
\r
264 the <emphasis><rev></emphasis> before <emphasis>^</emphasis>.
\r
270 <emphasis>:/<text></emphasis>, e.g. <emphasis>:/fix nasty bug</emphasis>
\r
274 A colon, followed by a slash, followed by a text, names
\r
275 a commit whose commit message matches the specified regular expression.
\r
276 This name returns the youngest matching commit which is
\r
277 reachable from any ref. If the commit message starts with a
\r
278 <emphasis>!</emphasis> you have to repeat that; the special sequence <emphasis>:/!</emphasis>,
\r
279 followed by something else than <emphasis>!</emphasis>, is reserved for now.
\r
280 The regular expression can match any part of the commit message. To
\r
281 match messages starting with a string, one can use e.g. <emphasis>:/^foo</emphasis>.
\r
287 <emphasis><rev>:<path></emphasis>, e.g. <emphasis>HEAD:README</emphasis>, <emphasis>:README</emphasis>, <emphasis>master:./README</emphasis>
\r
291 A suffix <emphasis>:</emphasis> followed by a path names the blob or tree
\r
292 at the given path in the tree-ish object named by the part
\r
294 <emphasis>:path</emphasis> (with an empty part before the colon)
\r
295 is a special case of the syntax described next: content
\r
296 recorded in the index at the given path.
\r
297 A path starting with <emphasis>./</emphasis> or <emphasis>../</emphasis> is relative to the current working directory.
\r
298 The given path will be converted to be relative to the working tree's root directory.
\r
299 This is most useful to address a blob or tree from a commit or tree that has
\r
300 the same tree structure as the working tree.
\r
306 <emphasis>:<n>:<path></emphasis>, e.g. <emphasis>:0:README</emphasis>, <emphasis>:README</emphasis>
\r
310 A colon, optionally followed by a stage number (0 to 3) and a
\r
311 colon, followed by a path, names a blob object in the
\r
312 index at the given path. A missing stage number (and the colon
\r
313 that follows it) names a stage 0 entry. During a merge, stage
\r
314 1 is the common ancestor, stage 2 is the target branch's version
\r
315 (typically the current branch), and stage 3 is the version from
\r
316 the branch which is being merged.
\r
321 <simpara>Here is an illustration, by Jon Loeliger. Both commit nodes B
\r
322 and C are parents of commit node A. Parent commits are ordered
\r
323 left-to-right.</simpara>
\r
324 <literallayout class="monospaced">G H I J
\r
334 <literallayout class="monospaced">A = = A^0
\r
337 D = A^^ = A^1^1 = A~2
\r
340 G = A^^^ = A^1^1^1 = A~3
\r
341 H = D^2 = B^^2 = A^^^2 = A~2^2
\r
342 I = F^ = B^3^ = A^^3^
\r
343 J = F^2 = B^3^2 = A^^3^2</literallayout>
\r
345 <simplesect id="gitrevisions(7)__specifying_ranges">
\r
346 <title>SPECIFYING RANGES</title>
\r
347 <simpara>History traversing commands such as <emphasis>git log</emphasis> operate on a set
\r
348 of commits, not just a single commit. To these commands,
\r
349 specifying a single revision with the notation described in the
\r
350 previous section means the set of commits reachable from that
\r
351 commit, following the commit ancestry chain.</simpara>
\r
352 <simpara>To exclude commits reachable from a commit, a prefix <emphasis>^</emphasis>
\r
353 notation is used. E.g. <emphasis>^r1 r2</emphasis> means commits reachable
\r
354 from <emphasis>r2</emphasis> but exclude the ones reachable from <emphasis>r1</emphasis>.</simpara>
\r
355 <simpara>This set operation appears so often that there is a shorthand
\r
356 for it. When you have two commits <emphasis>r1</emphasis> and <emphasis>r2</emphasis> (named according
\r
357 to the syntax explained in SPECIFYING REVISIONS above), you can ask
\r
358 for commits that are reachable from r2 excluding those that are reachable
\r
359 from r1 by <emphasis>^r1 r2</emphasis> and it can be written as <emphasis>r1..r2</emphasis>.</simpara>
\r
360 <simpara>A similar notation <emphasis>r1...r2</emphasis> is called symmetric difference
\r
361 of <emphasis>r1</emphasis> and <emphasis>r2</emphasis> and is defined as
\r
362 <emphasis>r1 r2 --not $(git merge-base --all r1 r2)</emphasis>.
\r
363 It is the set of commits that are reachable from either one of
\r
364 <emphasis>r1</emphasis> or <emphasis>r2</emphasis> but not from both.</simpara>
\r
365 <simpara>In these two shorthands, you can omit one end and let it default to HEAD.
\r
366 For example, <emphasis>origin..</emphasis> is a shorthand for <emphasis>origin..HEAD</emphasis> and asks "What
\r
367 did I do since I forked from the origin branch?" Similarly, <emphasis>..origin</emphasis>
\r
368 is a shorthand for <emphasis>HEAD..origin</emphasis> and asks "What did the origin do since
\r
369 I forked from them?" Note that <emphasis>..</emphasis> would mean <emphasis>HEAD..HEAD</emphasis> which is an
\r
370 empty range that is both reachable and unreachable from HEAD.</simpara>
\r
371 <simpara>Two other shorthands for naming a set that is formed by a commit
\r
372 and its parent commits exist. The <emphasis>r1^@</emphasis> notation means all
\r
373 parents of <emphasis>r1</emphasis>. <emphasis>r1^!</emphasis> includes commit <emphasis>r1</emphasis> but excludes
\r
374 all of its parents.</simpara>
\r
375 <simpara>To summarize:</simpara>
\r
379 <emphasis><rev></emphasis>
\r
383 Include commits that are reachable from (i.e. ancestors of)
\r
390 <emphasis>^<rev></emphasis>
\r
394 Exclude commits that are reachable from (i.e. ancestors of)
\r
401 <emphasis><rev1>..<rev2></emphasis>
\r
405 Include commits that are reachable from <rev2> but exclude
\r
406 those that are reachable from <rev1>.
\r
412 <emphasis><rev1>...<rev2></emphasis>
\r
416 Include commits that are reachable from either <rev1> or
\r
417 <rev2> but exclude those that are reachable from both.
\r
423 <emphasis><rev>^@</emphasis>, e.g. <emphasis>HEAD^@</emphasis>
\r
427 A suffix <emphasis>^</emphasis> followed by an at sign is the same as listing
\r
428 all parents of <emphasis><rev></emphasis> (meaning, include anything reachable from
\r
429 its parents, but not the commit itself).
\r
435 <emphasis><rev>^!</emphasis>, e.g. <emphasis>HEAD^!</emphasis>
\r
439 A suffix <emphasis>^</emphasis> followed by an exclamation mark is the same
\r
440 as giving commit <emphasis><rev></emphasis> and then all its parents prefixed with
\r
441 <emphasis>^</emphasis> to exclude them (and their ancestors).
\r
446 <simpara>Here are a handful of examples:</simpara>
\r
447 <literallayout class="monospaced">D G H D
\r
457 F^! D G H D F</literallayout>
\r
459 <simplesect id="gitrevisions(7)__see_also">
\r
460 <title>SEE ALSO</title>
\r
461 <simpara><xref linkend="git-rev-parse(1)" /></simpara>
\r
463 <simplesect id="gitrevisions(7)__git">
\r
465 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r