updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / gitcli.xml
blob25734e99f5657f070d8ab7543e50253abb1228a5
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="gitcli(7)">\r
5 <articleinfo>\r
6     <title>gitcli(7)</title>\r
7 <indexterm>\r
8 <primary>gitcli(7)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>gitcli - git command line interface and conventions</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <simpara>gitcli</simpara>\r
18 </simplesect>\r
19 <simplesect id="_description">\r
20 <title>DESCRIPTION</title>\r
21 <simpara>This manual describes the convention used throughout git CLI.</simpara>\r
22 <simpara>Many commands take revisions (most often "commits", but sometimes\r
23 "tree-ish", depending on the context and command) and paths as their\r
24 arguments.  Here are the rules:</simpara>\r
25 <itemizedlist>\r
26 <listitem>\r
27 <simpara>\r
28 Revisions come first and then paths.\r
29    E.g. in <emphasis>git diff v1.0 v2.0 arch/x86 include/asm-x86</emphasis>,\r
30    <emphasis>v1.0</emphasis> and <emphasis>v2.0</emphasis> are revisions and <emphasis>arch/x86</emphasis> and <emphasis>include/asm-x86</emphasis>\r
31    are paths.\r
32 </simpara>\r
33 </listitem>\r
34 <listitem>\r
35 <simpara>\r
36 When an argument can be misunderstood as either a revision or a path,\r
37    they can be disambiguated by placing <emphasis>--</emphasis> between them.\r
38    E.g. <emphasis>git diff -- HEAD</emphasis> is, "I have a file called HEAD in my work\r
39    tree.  Please show changes between the version I staged in the index\r
40    and what I have in the work tree for that file". not "show difference\r
41    between the HEAD commit and the work tree as a whole".  You can say\r
42    <emphasis>git diff HEAD --</emphasis> to ask for the latter.\r
43 </simpara>\r
44 </listitem>\r
45 <listitem>\r
46 <simpara>\r
47 Without disambiguating <emphasis>--</emphasis>, git makes a reasonable guess, but errors\r
48    out and asking you to disambiguate when ambiguous.  E.g. if you have a\r
49    file called HEAD in your work tree, <emphasis>git diff HEAD</emphasis> is ambiguous, and\r
50    you have to say either <emphasis>git diff HEAD --</emphasis> or <emphasis>git diff -- HEAD</emphasis> to\r
51    disambiguate.\r
52 </simpara>\r
53 </listitem>\r
54 </itemizedlist>\r
55 <simpara>When writing a script that is expected to handle random user-input, it is\r
56 a good practice to make it explicit which arguments are which by placing\r
57 disambiguating <emphasis>--</emphasis> at appropriate places.</simpara>\r
58 <simpara>Here are the rules regarding the "flags" that you should follow when you are\r
59 scripting git:</simpara>\r
60 <itemizedlist>\r
61 <listitem>\r
62 <simpara>\r
63 it's preferred to use the non dashed form of git commands, which means that\r
64    you should prefer <emphasis>git foo</emphasis> to <emphasis>git-foo</emphasis>.\r
65 </simpara>\r
66 </listitem>\r
67 <listitem>\r
68 <simpara>\r
69 splitting short options to separate words (prefer <emphasis>git foo -a -b</emphasis>\r
70    to <emphasis>git foo -ab</emphasis>, the latter may not even work).\r
71 </simpara>\r
72 </listitem>\r
73 <listitem>\r
74 <simpara>\r
75 when a command line option takes an argument, use the <emphasis>sticked</emphasis> form.  In\r
76    other words, write <emphasis>git foo -oArg</emphasis> instead of <emphasis>git foo -o Arg</emphasis> for short\r
77    options, and <emphasis>git foo --long-opt=Arg</emphasis> instead of <emphasis>git foo --long-opt Arg</emphasis>\r
78    for long options.  An option that takes optional option-argument must be\r
79    written in the <emphasis>sticked</emphasis> form.\r
80 </simpara>\r
81 </listitem>\r
82 <listitem>\r
83 <simpara>\r
84 when you give a revision parameter to a command, make sure the parameter is\r
85    not ambiguous with a name of a file in the work tree.  E.g. do not write\r
86    <emphasis>git log -1 HEAD</emphasis> but write <emphasis>git log -1 HEAD --</emphasis>; the former will not work\r
87    if you happen to have a file called <emphasis>HEAD</emphasis> in the work tree.\r
88 </simpara>\r
89 </listitem>\r
90 </itemizedlist>\r
91 </simplesect>\r
92 <simplesect id="_enhanced_option_parser">\r
93 <title>ENHANCED OPTION PARSER</title>\r
94 <simpara>From the git 1.5.4 series and further, many git commands (not all of them at the\r
95 time of the writing though) come with an enhanced option parser.</simpara>\r
96 <simpara>Here is an exhaustive list of the facilities provided by this option parser.</simpara>\r
97 <section id="_magic_options">\r
98 <title>Magic Options</title>\r
99 <simpara>Commands which have the enhanced option parser activated all understand a\r
100 couple of magic command line options:</simpara>\r
101 <variablelist>\r
102 <varlistentry>\r
103 <term>\r
104 -h\r
105 </term>\r
106 <listitem>\r
107 <simpara>\r
108         gives a pretty printed usage of the command.\r
109 </simpara>\r
110 <screen>$ git describe -h\r
111 usage: git describe [options] &lt;committish&gt;*\r
113     --contains            find the tag that comes after the commit\r
114     --debug               debug search strategy on stderr\r
115     --all                 use any ref in .git/refs\r
116     --tags                use any tag in .git/refs/tags\r
117     --abbrev [&lt;n&gt;]        use &lt;n&gt; digits to display SHA-1s\r
118     --candidates &lt;n&gt;      consider &lt;n&gt; most recent tags (default: 10)</screen>\r
119 </listitem>\r
120 </varlistentry>\r
121 <varlistentry>\r
122 <term>\r
123 --help-all\r
124 </term>\r
125 <listitem>\r
126 <simpara>\r
127         Some git commands take options that are only used for plumbing or that\r
128         are deprecated, and such options are hidden from the default usage. This\r
129         option gives the full list of options.\r
130 </simpara>\r
131 </listitem>\r
132 </varlistentry>\r
133 </variablelist>\r
134 </section>\r
135 <section id="_negating_options">\r
136 <title>Negating options</title>\r
137 <simpara>Options with long option names can be negated by prefixing <emphasis>--no-</emphasis>. For\r
138 example, <emphasis>git branch</emphasis> has the option <emphasis>--track</emphasis> which is <emphasis>on</emphasis> by default. You\r
139 can use <emphasis>--no-track</emphasis> to override that behaviour. The same goes for <emphasis>--color</emphasis>\r
140 and <emphasis>--no-color</emphasis>.</simpara>\r
141 </section>\r
142 <section id="_aggregating_short_options">\r
143 <title>Aggregating short options</title>\r
144 <simpara>Commands that support the enhanced option parser allow you to aggregate short\r
145 options. This means that you can for example use <emphasis>git rm -rf</emphasis> or\r
146 <emphasis>git clean -fdx</emphasis>.</simpara>\r
147 </section>\r
148 <section id="_separating_argument_from_the_option">\r
149 <title>Separating argument from the option</title>\r
150 <simpara>You can write the mandatory option parameter to an option as a separate\r
151 word on the command line.  That means that all the following uses work:</simpara>\r
152 <screen>$ git foo --long-opt=Arg\r
153 $ git foo --long-opt Arg\r
154 $ git foo -oArg\r
155 $ git foo -o Arg</screen>\r
156 <simpara>However, this is <emphasis role="strong">NOT</emphasis> allowed for switches with an optional value, where the\r
157 <emphasis>sticked</emphasis> form must be used:</simpara>\r
158 <screen>$ git describe --abbrev HEAD     # correct\r
159 $ git describe --abbrev=10 HEAD  # correct\r
160 $ git describe --abbrev 10 HEAD  # NOT WHAT YOU MEANT</screen>\r
161 </section>\r
162 </simplesect>\r
163 <simplesect id="_notes_on_frequently_confused_options">\r
164 <title>NOTES ON FREQUENTLY CONFUSED OPTIONS</title>\r
165 <simpara>Many commands that can work on files in the working tree\r
166 and/or in the index can take <emphasis>--cached</emphasis> and/or <emphasis>--index</emphasis>\r
167 options.  Sometimes people incorrectly think that, because\r
168 the index was originally called cache, these two are\r
169 synonyms.  They are <emphasis role="strong">not</emphasis> -- these two options mean very\r
170 different things.</simpara>\r
171 <itemizedlist>\r
172 <listitem>\r
173 <simpara>\r
174 The <emphasis>--cached</emphasis> option is used to ask a command that\r
175    usually works on files in the working tree to <emphasis role="strong">only</emphasis> work\r
176    with the index.  For example, <emphasis>git grep</emphasis>, when used\r
177    without a commit to specify from which commit to look for\r
178    strings in, usually works on files in the working tree,\r
179    but with the <emphasis>--cached</emphasis> option, it looks for strings in\r
180    the index.\r
181 </simpara>\r
182 </listitem>\r
183 <listitem>\r
184 <simpara>\r
185 The <emphasis>--index</emphasis> option is used to ask a command that\r
186    usually works on files in the working tree to <emphasis role="strong">also</emphasis>\r
187    affect the index.  For example, <emphasis>git stash apply</emphasis> usually\r
188    merges changes recorded in a stash to the working tree,\r
189    but with the <emphasis>--index</emphasis> option, it also merges changes to\r
190    the index as well.\r
191 </simpara>\r
192 </listitem>\r
193 </itemizedlist>\r
194 <simpara><emphasis>git apply</emphasis> command can be used with <emphasis>--cached</emphasis> and\r
195 <emphasis>--index</emphasis> (but not at the same time).  Usually the command\r
196 only affects the files in the working tree, but with\r
197 <emphasis>--index</emphasis>, it patches both the files and their index\r
198 entries, and with <emphasis>--cached</emphasis>, it modifies only the index\r
199 entries.</simpara>\r
200 <simpara>See also <ulink url="http://marc.info/?l=git&amp;m=116563135620359">http://marc.info/?l=git&amp;m=116563135620359</ulink> and\r
201 <ulink url="http://marc.info/?l=git&amp;m=119150393620273">http://marc.info/?l=git&amp;m=119150393620273</ulink> for further\r
202 information.</simpara>\r
203 </simplesect>\r
204 <simplesect id="_git">\r
205 <title>GIT</title>\r
206 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
207 </simplesect>\r
208 </article>\r