]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/gitcli.txt
Git 1.8.4.4
[thirdparty/git.git] / Documentation / gitcli.txt
CommitLineData
a5af0e2c 1gitcli(7)
2f7ee089
PH
2=========
3
4NAME
5----
2de9b711 6gitcli - Git command line interface and conventions
2f7ee089
PH
7
8SYNOPSIS
9--------
10gitcli
11
12
13DESCRIPTION
14-----------
15
2de9b711 16This manual describes the convention used throughout Git CLI.
d0658ec6
JH
17
18Many commands take revisions (most often "commits", but sometimes
19"tree-ish", depending on the context and command) and paths as their
20arguments. Here are the rules:
21
22 * Revisions come first and then paths.
23 E.g. in `git diff v1.0 v2.0 arch/x86 include/asm-x86`,
24 `v1.0` and `v2.0` are revisions and `arch/x86` and `include/asm-x86`
25 are paths.
26
27 * When an argument can be misunderstood as either a revision or a path,
6cf378f0
JK
28 they can be disambiguated by placing `--` between them.
29 E.g. `git diff -- HEAD` is, "I have a file called HEAD in my work
d0658ec6
JH
30 tree. Please show changes between the version I staged in the index
31 and what I have in the work tree for that file". not "show difference
32 between the HEAD commit and the work tree as a whole". You can say
6cf378f0 33 `git diff HEAD --` to ask for the latter.
d0658ec6 34
2de9b711 35 * Without disambiguating `--`, Git makes a reasonable guess, but errors
d0658ec6
JH
36 out and asking you to disambiguate when ambiguous. E.g. if you have a
37 file called HEAD in your work tree, `git diff HEAD` is ambiguous, and
6cf378f0 38 you have to say either `git diff HEAD --` or `git diff -- HEAD` to
d0658ec6 39 disambiguate.
008566e0 40+
d0658ec6
JH
41When writing a script that is expected to handle random user-input, it is
42a good practice to make it explicit which arguments are which by placing
6cf378f0 43disambiguating `--` at appropriate places.
d0658ec6 44
8300016e
JH
45 * Many commands allow wildcards in paths, but you need to protect
46 them from getting globbed by the shell. These two mean different
47 things:
48+
49--------------------------------
50$ git checkout -- *.c
51$ git checkout -- \*.c
52--------------------------------
53+
54The former lets your shell expand the fileglob, and you are asking
55the dot-C files in your working tree to be overwritten with the version
56in the index. The latter passes the `*.c` to Git, and you are asking
57the paths in the index that match the pattern to be checked out to your
58working tree. After running `git add hello.c; rm hello.c`, you will _not_
59see `hello.c` in your working tree with the former, but with the latter
60you will.
61
d0658ec6 62Here are the rules regarding the "flags" that you should follow when you are
2de9b711 63scripting Git:
2f7ee089 64
2de9b711 65 * it's preferred to use the non dashed form of Git commands, which means that
dcb11263 66 you should prefer `git foo` to `git-foo`.
2f7ee089 67
dcb11263
CJ
68 * splitting short options to separate words (prefer `git foo -a -b`
69 to `git foo -ab`, the latter may not even work).
2f7ee089
PH
70
71 * when a command line option takes an argument, use the 'sticked' form. In
dcb11263
CJ
72 other words, write `git foo -oArg` instead of `git foo -o Arg` for short
73 options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg`
2f7ee089
PH
74 for long options. An option that takes optional option-argument must be
75 written in the 'sticked' form.
76
77 * when you give a revision parameter to a command, make sure the parameter is
78 not ambiguous with a name of a file in the work tree. E.g. do not write
dcb11263 79 `git log -1 HEAD` but write `git log -1 HEAD --`; the former will not work
2f7ee089
PH
80 if you happen to have a file called `HEAD` in the work tree.
81
9c81990b
JH
82 * many commands allow a long option "--option" to be abbreviated
83 only to their unique prefix (e.g. if there is no other option
84 whose name begins with "opt", you may be able to spell "--opt" to
85 invoke the "--option" flag), but you should fully spell them out
86 when writing your scripts; later versions of Git may introduce a
87 new option whose name shares the same prefix, e.g. "--optimize",
88 to make a short prefix that used to be unique no longer unique.
89
2f7ee089 90
d0658ec6
JH
91ENHANCED OPTION PARSER
92----------------------
2de9b711 93From the Git 1.5.4 series and further, many Git commands (not all of them at the
2f7ee089
PH
94time of the writing though) come with an enhanced option parser.
95
30462a74 96Here is a list of the facilities provided by this option parser.
2f7ee089
PH
97
98
99Magic Options
100~~~~~~~~~~~~~
101Commands which have the enhanced option parser activated all understand a
102couple of magic command line options:
103
104-h::
105 gives a pretty printed usage of the command.
106+
107---------------------------------------------
108$ git describe -h
3ddcb198 109usage: git describe [options] <committish>*
48dfe969 110 or: git describe [options] --dirty
2f7ee089
PH
111
112 --contains find the tag that comes after the commit
113 --debug debug search strategy on stderr
48dfe969
GP
114 --all use any ref
115 --tags use any tag, even unannotated
116 --long always use long format
117 --abbrev[=<n>] use <n> digits to display SHA-1s
2f7ee089
PH
118---------------------------------------------
119
120--help-all::
2de9b711 121 Some Git commands take options that are only used for plumbing or that
2f7ee089
PH
122 are deprecated, and such options are hidden from the default usage. This
123 option gives the full list of options.
124
125
126Negating options
127~~~~~~~~~~~~~~~~
dcb11263
CJ
128Options with long option names can be negated by prefixing `--no-`. For
129example, `git branch` has the option `--track` which is 'on' by default. You
130can use `--no-track` to override that behaviour. The same goes for `--color`
131and `--no-color`.
2f7ee089
PH
132
133
134Aggregating short options
135~~~~~~~~~~~~~~~~~~~~~~~~~
136Commands that support the enhanced option parser allow you to aggregate short
dcb11263
CJ
137options. This means that you can for example use `git rm -rf` or
138`git clean -fdx`.
2f7ee089
PH
139
140
30462a74
JH
141Abbreviating long options
142~~~~~~~~~~~~~~~~~~~~~~~~~
143Commands that support the enhanced option parser accepts unique
144prefix of a long option as if it is fully spelled out, but use this
145with a caution. For example, `git commit --amen` behaves as if you
146typed `git commit --amend`, but that is true only until a later version
147of Git introduces another option that shares the same prefix,
148e.g `git commit --amenity" option.
149
150
2f7ee089
PH
151Separating argument from the option
152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153You can write the mandatory option parameter to an option as a separate
154word on the command line. That means that all the following uses work:
155
156----------------------------
157$ git foo --long-opt=Arg
158$ git foo --long-opt Arg
159$ git foo -oArg
160$ git foo -o Arg
161----------------------------
162
f1cdcc70 163However, this is *NOT* allowed for switches with an optional value, where the
2f7ee089
PH
164'sticked' form must be used:
165----------------------------
166$ git describe --abbrev HEAD # correct
167$ git describe --abbrev=10 HEAD # correct
168$ git describe --abbrev 10 HEAD # NOT WHAT YOU MEANT
169----------------------------
170
171
aa0c1f20
NS
172NOTES ON FREQUENTLY CONFUSED OPTIONS
173------------------------------------
174
175Many commands that can work on files in the working tree
176and/or in the index can take `--cached` and/or `--index`
177options. Sometimes people incorrectly think that, because
178the index was originally called cache, these two are
179synonyms. They are *not* -- these two options mean very
180different things.
181
182 * The `--cached` option is used to ask a command that
183 usually works on files in the working tree to *only* work
184 with the index. For example, `git grep`, when used
185 without a commit to specify from which commit to look for
186 strings in, usually works on files in the working tree,
187 but with the `--cached` option, it looks for strings in
188 the index.
189
190 * The `--index` option is used to ask a command that
191 usually works on files in the working tree to *also*
192 affect the index. For example, `git stash apply` usually
193 merges changes recorded in a stash to the working tree,
194 but with the `--index` option, it also merges changes to
195 the index as well.
196
197`git apply` command can be used with `--cached` and
198`--index` (but not at the same time). Usually the command
199only affects the files in the working tree, but with
200`--index`, it patches both the files and their index
201entries, and with `--cached`, it modifies only the index
202entries.
203
204See also http://marc.info/?l=git&m=116563135620359 and
205http://marc.info/?l=git&m=119150393620273 for further
206information.
207
2f7ee089
PH
208GIT
209---
9e1f0a85 210Part of the linkgit:git[1] suite