updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitrevisions.xml
blobb2b87a61c0f13ca3621409195b0c6d377c94d6be
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="gitrevisions(7)">\r
5 <articleinfo>\r
6     <title>gitrevisions(7)</title>\r
7 <indexterm>\r
8 <primary>gitrevisions(7)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>gitrevisions - specifying revisions and ranges for git</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara>gitrevisions</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>Many Git commands take revision parameters as arguments. Depending on\r
22 the command, they denote a specific commit or, for commands which\r
23 walk the revision graph (such as <xref linkend="git-log(1)" />), all commits which can\r
24 be reached from that commit. In the latter case one can also specify a\r
25 range of revisions explicitly.</simpara>\r
26 <simpara>In addition, some Git commands (such as <xref linkend="git-show(1)" />) also take\r
27 revision parameters which denote other objects than commits, e.g. blobs\r
28 ("files") or trees ("directories of files").</simpara>\r
29 </simplesect>\r
30 <simplesect id="_specifying_revisions">\r
31 <title>SPECIFYING REVISIONS</title>\r
32 <simpara>A revision parameter <emphasis>&lt;rev&gt;</emphasis> typically, but not necessarily, names a\r
33 commit object.  It uses what is called an <emphasis>extended SHA1</emphasis>\r
34 syntax.  Here are various ways to spell object names.  The\r
35 ones listed near the end of this list name trees and\r
36 blobs contained in a commit.</simpara>\r
37 <variablelist>\r
38 <varlistentry>\r
39 <term>\r
40 <emphasis>&lt;sha1&gt;</emphasis>, e.g. <emphasis>dae86e1950b1277e545cee180551750029cfe735</emphasis>, <emphasis>dae86e</emphasis>\r
41 </term>\r
42 <listitem>\r
43 <simpara>\r
44   The full SHA1 object name (40-byte hexadecimal string), or\r
45   a leading substring that is unique within the repository.\r
46   E.g. dae86e1950b1277e545cee180551750029cfe735 and dae86e both\r
47   name the same commit object if there is no other object in\r
48   your repository whose object name starts with dae86e.\r
49 </simpara>\r
50 </listitem>\r
51 </varlistentry>\r
52 <varlistentry>\r
53 <term>\r
54 <emphasis>&lt;describeOutput&gt;</emphasis>, e.g. <emphasis>v1.7.4.2-679-g3bee7fb</emphasis>\r
55 </term>\r
56 <listitem>\r
57 <simpara>\r
58   Output from <emphasis>git describe</emphasis>; i.e. a closest tag, optionally\r
59   followed by a dash and a number of commits, followed by a dash, a\r
60   <emphasis>g</emphasis>, and an abbreviated object name.\r
61 </simpara>\r
62 </listitem>\r
63 </varlistentry>\r
64 <varlistentry>\r
65 <term>\r
66 <emphasis>&lt;refname&gt;</emphasis>, e.g. <emphasis>master</emphasis>, <emphasis>heads/master</emphasis>, <emphasis>refs/heads/master</emphasis>\r
67 </term>\r
68 <listitem>\r
69 <simpara>\r
70   A symbolic ref name.  E.g. <emphasis>master</emphasis> typically means the commit\r
71   object referenced by <emphasis>refs/heads/master</emphasis>.  If you\r
72   happen to have both <emphasis>heads/master</emphasis> and <emphasis>tags/master</emphasis>, you can\r
73   explicitly say <emphasis>heads/master</emphasis> to tell git which one you mean.\r
74   When ambiguous, a <emphasis>&lt;name&gt;</emphasis> is disambiguated by taking the\r
75   first match in the following rules:\r
76 </simpara>\r
77 <orderedlist numeration="arabic">\r
78 <listitem>\r
79 <simpara>\r
80 If <emphasis>$GIT_DIR/&lt;name&gt;</emphasis> exists, that is what you mean (this is usually\r
81     useful only for <emphasis>HEAD</emphasis>, <emphasis>FETCH_HEAD</emphasis>, <emphasis>ORIG_HEAD</emphasis>, <emphasis>MERGE_HEAD</emphasis>\r
82     and <emphasis>CHERRY_PICK_HEAD</emphasis>);\r
83 </simpara>\r
84 </listitem>\r
85 <listitem>\r
86 <simpara>\r
87 otherwise, <emphasis>refs/&lt;name&gt;</emphasis> if it exists;\r
88 </simpara>\r
89 </listitem>\r
90 <listitem>\r
91 <simpara>\r
92 otherwise, <emphasis>refs/tags/&lt;refname&gt;</emphasis> if it exists;\r
93 </simpara>\r
94 </listitem>\r
95 <listitem>\r
96 <simpara>\r
97 otherwise, <emphasis>refs/heads/&lt;name&gt;</emphasis> if it exists;\r
98 </simpara>\r
99 </listitem>\r
100 <listitem>\r
101 <simpara>\r
102 otherwise, <emphasis>refs/remotes/&lt;name&gt;</emphasis> if it exists;\r
103 </simpara>\r
104 </listitem>\r
105 <listitem>\r
106 <simpara>\r
107 otherwise, <emphasis>refs/remotes/&lt;name&gt;/HEAD</emphasis> if it exists.\r
108 </simpara>\r
109 <simpara><emphasis>HEAD</emphasis> names the commit on which you based the changes in the working tree.\r
110 <emphasis>FETCH_HEAD</emphasis> records the branch which you fetched from a remote repository\r
111 with your last <emphasis>git fetch</emphasis> invocation.\r
112 <emphasis>ORIG_HEAD</emphasis> is created by commands that move your <emphasis>HEAD</emphasis> in a drastic\r
113 way, to record the position of the <emphasis>HEAD</emphasis> before their operation, so that\r
114 you can easily change the tip of the branch back to the state before you ran\r
115 them.\r
116 <emphasis>MERGE_HEAD</emphasis> records the commit(s) which you are merging into your branch\r
117 when you run <emphasis>git merge</emphasis>.\r
118 <emphasis>CHERRY_PICK_HEAD</emphasis> records the commit which you are cherry-picking\r
119 when you run <emphasis>git cherry-pick</emphasis>.</simpara>\r
120 <simpara>Note that any of the <emphasis>refs/*</emphasis> cases above may come either from\r
121 the <emphasis>$GIT_DIR/refs</emphasis> directory or from the <emphasis>$GIT_DIR/packed-refs</emphasis> file.</simpara>\r
122 </listitem>\r
123 </orderedlist>\r
124 </listitem>\r
125 </varlistentry>\r
126 <varlistentry>\r
127 <term>\r
128 <emphasis>&lt;refname&gt;@{&lt;date&gt;}</emphasis>, e.g. <emphasis>master@{yesterday}</emphasis>, <emphasis>HEAD@{5 minutes ago}</emphasis>\r
129 </term>\r
130 <listitem>\r
131 <simpara>\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/&lt;ref&gt;</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
142 </simpara>\r
143 </listitem>\r
144 </varlistentry>\r
145 <varlistentry>\r
146 <term>\r
147 <emphasis>&lt;refname&gt;@{&lt;n&gt;}</emphasis>, e.g. <emphasis>master@{1}</emphasis>\r
148 </term>\r
149 <listitem>\r
150 <simpara>\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/&lt;refname&gt;</emphasis>).\r
158 </simpara>\r
159 </listitem>\r
160 </varlistentry>\r
161 <varlistentry>\r
162 <term>\r
163 <emphasis>@{&lt;n&gt;}</emphasis>, e.g. <emphasis>@{1}</emphasis>\r
164 </term>\r
165 <listitem>\r
166 <simpara>\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
170 </simpara>\r
171 </listitem>\r
172 </varlistentry>\r
173 <varlistentry>\r
174 <term>\r
175 <emphasis>@{-&lt;n&gt;}</emphasis>, e.g. <emphasis>@{-1}</emphasis>\r
176 </term>\r
177 <listitem>\r
178 <simpara>\r
179   The construct <emphasis>@{-&lt;n&gt;}</emphasis> means the &lt;n&gt;th branch checked out\r
180   before the current one.\r
181 </simpara>\r
182 </listitem>\r
183 </varlistentry>\r
184 <varlistentry>\r
185 <term>\r
186 <emphasis>&lt;refname&gt;@{upstream}</emphasis>, e.g. <emphasis>master@{upstream}</emphasis>, <emphasis>@{u}</emphasis>\r
187 </term>\r
188 <listitem>\r
189 <simpara>\r
190   The suffix <emphasis>@{upstream}</emphasis> to a ref (short form <emphasis>&lt;refname&gt;@{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
193 </simpara>\r
194 </listitem>\r
195 </varlistentry>\r
196 <varlistentry>\r
197 <term>\r
198 <emphasis>&lt;rev&gt;&#94;</emphasis>, e.g. <emphasis>HEAD&#94;, v1.5.1&#94;0</emphasis>\r
199 </term>\r
200 <listitem>\r
201 <simpara>\r
202   A suffix <emphasis>&#94;</emphasis> to a revision parameter means the first parent of\r
203   that commit object.  <emphasis>&#94;&lt;n&gt;</emphasis> means the &lt;n&gt;th parent (i.e.\r
204   <emphasis>&lt;rev&gt;&#94;</emphasis>\r
205   is equivalent to <emphasis>&lt;rev&gt;&#94;1</emphasis>).  As a special rule,\r
206   <emphasis>&lt;rev&gt;&#94;0</emphasis> means the commit itself and is used when <emphasis>&lt;rev&gt;</emphasis> is the\r
207   object name of a tag object that refers to a commit object.\r
208 </simpara>\r
209 </listitem>\r
210 </varlistentry>\r
211 <varlistentry>\r
212 <term>\r
213 <emphasis>&lt;rev&gt;&#126;&lt;n&gt;</emphasis>, e.g. <emphasis>master&#126;3</emphasis>\r
214 </term>\r
215 <listitem>\r
216 <simpara>\r
217   A suffix <emphasis>&#126;&lt;n&gt;</emphasis> to a revision parameter means the commit\r
218   object that is the &lt;n&gt;th generation ancestor of the named\r
219   commit object, following only the first parents.  I.e. <emphasis>&lt;rev&gt;&#126;3</emphasis> is\r
220   equivalent to <emphasis>&lt;rev&gt;&#94;&#94;&#94;</emphasis> which is equivalent to\r
221   <emphasis>&lt;rev&gt;&#94;1&#94;1&#94;1</emphasis>.  See below for an illustration of\r
222   the usage of this form.\r
223 </simpara>\r
224 </listitem>\r
225 </varlistentry>\r
226 <varlistentry>\r
227 <term>\r
228 <emphasis>&lt;rev&gt;&#94;{&lt;type&gt;}</emphasis>, e.g. <emphasis>v0.99.8&#94;{commit}</emphasis>\r
229 </term>\r
230 <listitem>\r
231 <simpara>\r
232   A suffix <emphasis>&#94;</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>&lt;rev&gt;&#94;0</emphasis>\r
237   is a short-hand for <emphasis>&lt;rev&gt;&#94;{commit}</emphasis>.\r
238 </simpara>\r
239 </listitem>\r
240 </varlistentry>\r
241 <varlistentry>\r
242 <term>\r
243 <emphasis>&lt;rev&gt;&#94;{}</emphasis>, e.g. <emphasis>v0.99.8&#94;{}</emphasis>\r
244 </term>\r
245 <listitem>\r
246 <simpara>\r
247   A suffix <emphasis>&#94;</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
250   found.\r
251 </simpara>\r
252 </listitem>\r
253 </varlistentry>\r
254 <varlistentry>\r
255 <term>\r
256 <emphasis>&lt;rev&gt;&#94;{/&lt;text&gt;}</emphasis>, e.g. <emphasis>HEAD^{/fix nasty bug}</emphasis>\r
257 </term>\r
258 <listitem>\r
259 <simpara>\r
260   A suffix <emphasis>&#94;</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>&lt;rev&gt;</emphasis> before <emphasis>&#94;</emphasis>.\r
265 </simpara>\r
266 </listitem>\r
267 </varlistentry>\r
268 <varlistentry>\r
269 <term>\r
270 <emphasis>:/&lt;text&gt;</emphasis>, e.g. <emphasis>:/fix nasty bug</emphasis>\r
271 </term>\r
272 <listitem>\r
273 <simpara>\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
282 </simpara>\r
283 </listitem>\r
284 </varlistentry>\r
285 <varlistentry>\r
286 <term>\r
287 <emphasis>&lt;rev&gt;:&lt;path&gt;</emphasis>, e.g. <emphasis>HEAD:README</emphasis>, <emphasis>:README</emphasis>, <emphasis>master:./README</emphasis>\r
288 </term>\r
289 <listitem>\r
290 <simpara>\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
293   before the colon.\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
301 </simpara>\r
302 </listitem>\r
303 </varlistentry>\r
304 <varlistentry>\r
305 <term>\r
306 <emphasis>:&lt;n&gt;:&lt;path&gt;</emphasis>, e.g. <emphasis>:0:README</emphasis>, <emphasis>:README</emphasis>\r
307 </term>\r
308 <listitem>\r
309 <simpara>\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
317 </simpara>\r
318 </listitem>\r
319 </varlistentry>\r
320 </variablelist>\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
325  \ /     \ /\r
326   D   E   F\r
327    \  |  / \\r
328     \ | /   |\r
329      \|/    |\r
330       B     C\r
331        \   /\r
332         \ /\r
333          A</literallayout>\r
334 <literallayout class="monospaced">A =      = A^0\r
335 B = A^   = A^1     = A~1\r
336 C = A^2  = A^2\r
337 D = A^^  = A^1^1   = A~2\r
338 E = B^2  = A^^2\r
339 F = B^3  = A^^3\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
344 </simplesect>\r
345 <simplesect id="_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>&#94;</emphasis>\r
353 notation is used.  E.g. <emphasis>&#94;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>&#94;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>Two other shorthands for naming a set that is formed by a commit\r
366 and its parent commits exist.  The <emphasis>r1&#94;@</emphasis> notation means all\r
367 parents of <emphasis>r1</emphasis>.  <emphasis>r1&#94;!</emphasis> includes commit <emphasis>r1</emphasis> but excludes\r
368 all of its parents.</simpara>\r
369 <simpara>Here are a handful of examples:</simpara>\r
370 <literallayout class="monospaced">D                G H D\r
371 D F              G H I J D F\r
372 ^G D             H D\r
373 ^D B             E I J F B\r
374 B...C            G H D E B C\r
375 ^D B C           E I J F B C\r
376 C^@              I J F\r
377 F^! D            G H D F</literallayout>\r
378 </simplesect>\r
379 <simplesect id="_see_also">\r
380 <title>SEE ALSO</title>\r
381 <simpara><xref linkend="git-rev-parse(1)" /></simpara>\r
382 </simplesect>\r
383 <simplesect id="_git">\r
384 <title>GIT</title>\r
385 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
386 </simplesect>\r
387 </article>\r