2 .\" Title: gitrevisions
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.40.1.423.g2807bd2c10
10 .TH "GITREVISIONS" "7" "04/25/2023" "Git 2\&.40\&.1\&.423\&.g2807bd" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 gitrevisions \- Specifying revisions and ranges for Git
37 Many Git commands take revision parameters as arguments\&. Depending on the command, they denote a specific commit or, for commands which walk the revision graph (such as \fBgit-log\fR(1)), all commits which are reachable from that commit\&. For commands that walk the revision graph one can also specify a range of revisions explicitly\&.
39 In addition, some Git commands (such as \fBgit-show\fR(1) and \fBgit-push\fR(1)) can also take revision parameters which denote other objects than commits, e\&.g\&. blobs ("files") or trees ("directories of files")\&.
40 .SH "SPECIFYING REVISIONS"
42 A revision parameter \fI<rev>\fR typically, but not necessarily, names a commit object\&. It uses what is called an \fIextended SHA\-1\fR syntax\&. Here are various ways to spell object names\&. The ones listed near the end of this list name trees and blobs contained in a commit\&.
48 .nr an-no-space-flag 1
56 This document shows the "raw" syntax as seen by git\&. The shell and other UIs might require additional quoting to protect special characters and to avoid word splitting\&.
60 \fI<sha1>\fR, e\&.g\&. \fIdae86e1950b1277e545cee180551750029cfe735\fR, \fIdae86e\fR
62 The full SHA\-1 object name (40\-byte hexadecimal string), or a leading substring that is unique within the repository\&. E\&.g\&. dae86e1950b1277e545cee180551750029cfe735 and dae86e both name the same commit object if there is no other object in your repository whose object name starts with dae86e\&.
65 \fI<describeOutput>\fR, e\&.g\&. \fIv1\&.7\&.4\&.2\-679\-g3bee7fb\fR
68 \fBgit describe\fR; i\&.e\&. a closest tag, optionally followed by a dash and a number of commits, followed by a dash, a
69 \fIg\fR, and an abbreviated object name\&.
72 \fI<refname>\fR, e\&.g\&. \fImaster\fR, \fIheads/master\fR, \fIrefs/heads/master\fR
74 A symbolic ref name\&. E\&.g\&.
76 typically means the commit object referenced by
77 \fIrefs/heads/master\fR\&. If you happen to have both
80 \fItags/master\fR, you can explicitly say
82 to tell Git which one you mean\&. When ambiguous, a
84 is disambiguated by taking the first match in the following rules:
95 \fI$GIT_DIR/<refname>\fR
96 exists, that is what you mean (this is usually useful only for
102 \fBCHERRY_PICK_HEAD\fR);
127 \fIrefs/tags/<refname>\fR
140 \fIrefs/heads/<refname>\fR
153 \fIrefs/remotes/<refname>\fR
166 \fIrefs/remotes/<refname>/HEAD\fR
170 names the commit on which you based the changes in the working tree\&.
172 records the branch which you fetched from a remote repository with your last
176 is created by commands that move your
178 in a drastic way (\fBgit am\fR,
181 \fBgit reset\fR), to record the position of the
183 before their operation, so that you can easily change the tip of the branch back to the state before you ran them\&.
185 records the commit(s) which you are merging into your branch when you run
187 \fBCHERRY_PICK_HEAD\fR
188 records the commit which you are cherry\-picking when you run
189 \fBgit cherry\-pick\fR\&.
193 cases above may come either from the
195 directory or from the
196 \fB$GIT_DIR/packed\-refs\fR
197 file\&. While the ref name encoding is unspecified, UTF\-8 is preferred as some output processing may assume ref names in UTF\-8\&.
204 alone is a shortcut for
208 \fI[<refname>]@{<date>}\fR, e\&.g\&. \fImaster@{yesterday}\fR, \fIHEAD@{5 minutes ago}\fR
210 A ref followed by the suffix
212 with a date specification enclosed in a brace pair (e\&.g\&.
214 \fI{1 month 2 weeks 3 days 1 hour 1 second ago}\fR
216 \fI{1979\-02\-26 18:30:00}\fR) specifies the value of the ref at a prior point in time\&. This suffix may only be used immediately following a ref name and the ref must have an existing log (\fI$GIT_DIR/logs/<ref>\fR)\&. Note that this looks up the state of your
218 ref at a given time; e\&.g\&., what was in your local
220 branch last week\&. If you want to look at commits made during certain times, see
226 \fI<refname>@{<n>}\fR, e\&.g\&. \fImaster@{1}\fR
228 A ref followed by the suffix
230 with an ordinal specification enclosed in a brace pair (e\&.g\&.
232 \fI{15}\fR) specifies the n\-th prior value of that ref\&. For example
234 is the immediate prior value of
238 is the 5th prior value of
239 \fImaster\fR\&. This suffix may only be used immediately following a ref name and the ref must have an existing log (\fI$GIT_DIR/logs/<refname>\fR)\&.
242 \fI@{<n>}\fR, e\&.g\&. \fI@{1}\fR
246 construct with an empty ref part to get at a reflog entry of the current branch\&. For example, if you are on branch
254 \fI@{\-<n>}\fR, e\&.g\&. \fI@{\-1}\fR
258 means the <n>th branch/commit checked out before the current one\&.
261 \fI[<branchname>]@{upstream}\fR, e\&.g\&. \fImaster@{upstream}\fR, \fI@{u}\fR
263 A branch B may be set up to build on top of a branch X (configured with
264 \fBbranch\&.<name>\&.merge\fR) at a remote R (configured with the branch X taken from remote R, typically found at
265 \fBrefs/remotes/R/X\fR\&.
268 \fI[<branchname>]@{push}\fR, e\&.g\&. \fImaster@{push}\fR, \fI@{push}\fR
272 reports the branch "where we would push to" if
276 was checked out (or the current
278 if no branchname is specified)\&. Like for
279 \fI@{upstream}\fR, we report the remote\-tracking branch that corresponds to that branch at the remote\&.
281 Here\(cqs an example to make it more clear:
287 $ git config push\&.default current
288 $ git config remote\&.pushdefault myfork
289 $ git switch \-c mybranch origin/master
291 $ git rev\-parse \-\-symbolic\-full\-name @{upstream}
292 refs/remotes/origin/master
294 $ git rev\-parse \-\-symbolic\-full\-name @{push}
295 refs/remotes/myfork/mybranch
301 Note in the example that we set up a triangular workflow, where we pull from one location and push to another\&. In a non\-triangular workflow,
304 \fI@{upstream}\fR, and there is no need for it\&.
306 This suffix is also accepted when spelled in uppercase, and means the same thing no matter the case\&.
309 \fI<rev>^[<n>]\fR, e\&.g\&. \fIHEAD^, v1\&.5\&.1^0\fR
313 to a revision parameter means the first parent of that commit object\&.
315 means the <n>th parent (i\&.e\&.
318 \fI<rev>^1\fR)\&. As a special rule,
320 means the commit itself and is used when
322 is the object name of a tag object that refers to a commit object\&.
325 \fI<rev>~[<n>]\fR, e\&.g\&. \fIHEAD~, master~3\fR
329 to a revision parameter means the first parent of that commit object\&. A suffix
331 to a revision parameter means the commit object that is the <n>th generation ancestor of the named commit object, following only the first parents\&. I\&.e\&.
335 which is equivalent to
336 \fI<rev>^1^1^1\fR\&. See below for an illustration of the usage of this form\&.
339 \fI<rev>^{<type>}\fR, e\&.g\&. \fIv0\&.99\&.8^{commit}\fR
343 followed by an object type name enclosed in brace pair means dereference the object at
345 recursively until an object of type
347 is found or the object cannot be dereferenced anymore (in which case, barf)\&. For example, if
351 describes the corresponding commit object\&. Similarly, if
355 describes the corresponding tree object\&.
358 \fI<rev>^{commit}\fR\&.
361 can be used to make sure
363 names an object that exists, without requiring
365 to be a tag, and without dereferencing
366 \fI<rev>\fR; because a tag is already an object, it does not have to be dereferenced even once to get to an object\&.
369 can be used to ensure that
371 identifies an existing tag object\&.
374 \fI<rev>^{}\fR, e\&.g\&. \fIv0\&.99\&.8^{}\fR
378 followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non\-tag object is found\&.
381 \fI<rev>^{/<text>}\fR, e\&.g\&. \fIHEAD^{/fix nasty bug}\fR
385 to a revision parameter, followed by a brace pair that contains a text led by a slash, is the same as the
386 \fI:/fix nasty bug\fR
387 syntax below except that it returns the youngest matching commit which is reachable from the
393 \fI:/<text>\fR, e\&.g\&. \fI:/fix nasty bug\fR
395 A colon, followed by a slash, followed by a text, names a commit whose commit message matches the specified regular expression\&. This name returns the youngest matching commit which is reachable from any ref, including HEAD\&. The regular expression can match any part of the commit message\&. To match messages starting with a string, one can use e\&.g\&.
396 \fI:/^foo\fR\&. The special sequence
398 is reserved for modifiers to what is matched\&.
400 performs a negative match, while
404 character, followed by
405 \fIfoo\fR\&. Any other sequence beginning with
407 is reserved for now\&. Depending on the given text, the shell\(cqs word splitting rules might require additional quoting\&.
410 \fI<rev>:<path>\fR, e\&.g\&. \fIHEAD:README\fR, \fImaster:\&./README\fR
414 followed by a path names the blob or tree at the given path in the tree\-ish object named by the part before the colon\&. A path starting with
418 is relative to the current working directory\&. The given path will be converted to be relative to the working tree\(cqs root directory\&. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree\&.
421 \fI:[<n>:]<path>\fR, e\&.g\&. \fI:0:README\fR, \fI:README\fR
423 A colon, optionally followed by a stage number (0 to 3) and a colon, followed by a path, names a blob object in the index at the given path\&. A missing stage number (and the colon that follows it) names a stage 0 entry\&. During a merge, stage 1 is the common ancestor, stage 2 is the target branch\(cqs version (typically the current branch), and stage 3 is the version from the branch which is being merged\&.
426 Here is an illustration, by Jon Loeliger\&. Both commit nodes B and C are parents of commit node A\&. Parent commits are ordered left\-to\-right\&.
454 D = A^^ = A^1^1 = A~2
457 G = A^^^ = A^1^1^1 = A~3
458 H = D^2 = B^^2 = A^^^2 = A~2^2
459 I = F^ = B^3^ = A^^3^
460 J = F^2 = B^3^2 = A^^3^2
465 .SH "SPECIFYING RANGES"
467 History traversing commands such as \fBgit log\fR operate on a set of commits, not just a single commit\&.
469 For these commands, specifying a single revision, using the notation described in the previous section, means the set of commits \fBreachable\fR from the given commit\&.
471 Specifying several revisions means the set of commits reachable from any of the given commits\&.
473 A commit\(cqs reachable set is the commit itself and the commits in its ancestry chain\&.
475 There are several notations to specify a set of connected commits (called a "revision range"), illustrated below\&.
476 .SS "Commit Exclusions"
478 \fI^<rev>\fR (caret) Notation
480 To exclude commits reachable from a commit, a prefix
482 notation is used\&. E\&.g\&.
484 means commits reachable from
486 but exclude the ones reachable from
490 and its ancestors)\&.
492 .SS "Dotted Range Notations"
494 The \fI\&.\&.\fR (two\-dot) Range Notation
498 set operation appears so often that there is a shorthand for it\&. When you have two commits
502 (named according to the syntax explained in SPECIFYING REVISIONS above), you can ask for commits that are reachable from r2 excluding those that are reachable from r1 by
504 and it can be written as
508 The \fI\&.\&.\&.\fR (three\-dot) Symmetric Difference Notation
512 is called symmetric difference of
517 \fIr1 r2 \-\-not $(git merge\-base \-\-all r1 r2)\fR\&. It is the set of commits that are reachable from either one of
521 (right side) but not from both\&.
524 In these two shorthand notations, you can omit one end and let it default to HEAD\&. For example, \fIorigin\&.\&.\fR is a shorthand for \fIorigin\&.\&.HEAD\fR and asks "What did I do since I forked from the origin branch?" Similarly, \fI\&.\&.origin\fR is a shorthand for \fIHEAD\&.\&.origin\fR and asks "What did the origin do since I forked from them?" Note that \fI\&.\&.\fR would mean \fIHEAD\&.\&.HEAD\fR which is an empty range that is both reachable and unreachable from HEAD\&.
526 Commands that are specifically designed to take two distinct ranges (e\&.g\&. "git range\-diff R1 R2" to compare two ranges) do exist, but they are exceptions\&. Unless otherwise noted, all "git" commands that operate on a set of commits work on a single revision range\&. In other words, writing two "two\-dot range notation" next to each other, e\&.g\&.
532 $ git log A\&.\&.B C\&.\&.D
538 does \fBnot\fR specify two revision ranges for most commands\&. Instead it will name a single connected set of commits, i\&.e\&. those that are reachable from either B or D but are reachable from neither A or C\&. In a linear history like this:
544 \-\-\-A\-\-\-B\-\-\-o\-\-\-o\-\-\-C\-\-\-D
550 because A and B are reachable from C, the revision range specified by these two dotted ranges is a single commit D\&.
551 .SS "Other <rev>^ Parent Shorthand Notations"
553 Three other shorthands exist, particularly useful for merge commits, for naming a set that is formed by a commit and its parent commits\&.
555 The \fIr1^@\fR notation means all parents of \fIr1\fR\&.
557 The \fIr1^!\fR notation includes commit \fIr1\fR but excludes all of its parents\&. By itself, this notation denotes the single commit \fIr1\fR\&.
559 The \fI<rev>^\-[<n>]\fR notation includes \fI<rev>\fR but excludes the <n>th parent (i\&.e\&. a shorthand for \fI<rev>^<n>\&.\&.<rev>\fR), with \fI<n>\fR = 1 if not given\&. This is typically useful for merge commits where you can just pass \fI<commit>^\-\fR to get all the commits in the branch that was merged in merge commit \fI<commit>\fR (including \fI<commit>\fR itself)\&.
561 While \fI<rev>^<n>\fR was about specifying a single commit parent, these three notations also consider its parents\&. For example you can say \fIHEAD^2^@\fR, however you cannot say \fIHEAD^@^2\fR\&.
562 .SH "REVISION RANGE SUMMARY"
566 Include commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
571 Exclude commits that are reachable from <rev> (i\&.e\&. <rev> and its ancestors)\&.
574 \fI<rev1>\&.\&.<rev2>\fR
576 Include commits that are reachable from <rev2> but exclude those that are reachable from <rev1>\&. When either <rev1> or <rev2> is omitted, it defaults to
580 \fI<rev1>\&.\&.\&.<rev2>\fR
582 Include commits that are reachable from either <rev1> or <rev2> but exclude those that are reachable from both\&. When either <rev1> or <rev2> is omitted, it defaults to
586 \fI<rev>^@\fR, e\&.g\&. \fIHEAD^@\fR
590 followed by an at sign is the same as listing all parents of
592 (meaning, include anything reachable from its parents, but not the commit itself)\&.
595 \fI<rev>^!\fR, e\&.g\&. \fIHEAD^!\fR
599 followed by an exclamation mark is the same as giving commit
601 and all its parents prefixed with
603 to exclude them (and their ancestors)\&.
606 \fI<rev>^\-<n>\fR, e\&.g\&. \fIHEAD^\-, HEAD^\-2\fR
609 \fI<rev>^<n>\&.\&.<rev>\fR, with
614 Here are a handful of examples using the Loeliger illustration above, with each step in the notation\(cqs expansion and selection carefully spelt out:
620 Args Expanded arguments Selected commits
628 B\&.\&.\&.C = B ^F C G H D E B C
634 = D E F D G H E F I J
641 F^! D = F ^I ^J D G H D F
648 \fBgit-rev-parse\fR(1)
651 Part of the \fBgit\fR(1) suite