blob: f6ba90c2da8f381bc714762f24bbfc33fa82b356 [file] [log] [blame]
Junio C Hamano2fbcd212008-05-14 22:26:071gitcli(7)
Junio C Hamanof556fc22007-12-23 08:16:382=========
3
4NAME
5----
6gitcli - git command line interface and conventions
7
8SYNOPSIS
9--------
10gitcli
11
12
13DESCRIPTION
14-----------
15
Junio C Hamanoc4fec202008-06-28 10:07:2416This manual describes the convention used throughout git CLI.
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,
Junio C Hamanob76a6862012-05-02 22:02:4628 they can be disambiguated by placing `--` between them.
29 E.g. `git diff -- HEAD` is, "I have a file called HEAD in my work
Junio C Hamanoc4fec202008-06-28 10:07:2430 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
Junio C Hamanob76a6862012-05-02 22:02:4633 `git diff HEAD --` to ask for the latter.
Junio C Hamanoc4fec202008-06-28 10:07:2434
Junio C Hamanob76a6862012-05-02 22:02:4635 * Without disambiguating `--`, git makes a reasonable guess, but errors
Junio C Hamanoc4fec202008-06-28 10:07:2436 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
Junio C Hamanob76a6862012-05-02 22:02:4638 you have to say either `git diff HEAD --` or `git diff -- HEAD` to
Junio C Hamanoc4fec202008-06-28 10:07:2439 disambiguate.
Junio C Hamano693e7092012-09-12 22:56:5340+
Junio C Hamanoc4fec202008-06-28 10:07:2441When 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
Junio C Hamanob76a6862012-05-02 22:02:4643disambiguating `--` at appropriate places.
Junio C Hamanoc4fec202008-06-28 10:07:2444
Junio C Hamano693e7092012-09-12 22:56:5345 * 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
Junio C Hamanoc4fec202008-06-28 10:07:2462Here are the rules regarding the "flags" that you should follow when you are
63scripting git:
Junio C Hamanof556fc22007-12-23 08:16:3864
65 * it's preferred to use the non dashed form of git commands, which means that
Junio C Hamanoea82cff2009-03-18 01:54:4866 you should prefer `git foo` to `git-foo`.
Junio C Hamanof556fc22007-12-23 08:16:3867
Junio C Hamanoea82cff2009-03-18 01:54:4868 * splitting short options to separate words (prefer `git foo -a -b`
69 to `git foo -ab`, the latter may not even work).
Junio C Hamanof556fc22007-12-23 08:16:3870
71 * when a command line option takes an argument, use the 'sticked' form. In
Junio C Hamanoea82cff2009-03-18 01:54:4872 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`
Junio C Hamanof556fc22007-12-23 08:16:3874 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
Junio C Hamanoea82cff2009-03-18 01:54:4879 `git log -1 HEAD` but write `git log -1 HEAD --`; the former will not work
Junio C Hamanof556fc22007-12-23 08:16:3880 if you happen to have a file called `HEAD` in the work tree.
81
Junio C Hamanod0316112012-08-22 19:55:2982 * 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
Junio C Hamanof556fc22007-12-23 08:16:3890
Junio C Hamanoc4fec202008-06-28 10:07:2491ENHANCED OPTION PARSER
92----------------------
Junio C Hamanof556fc22007-12-23 08:16:3893From the git 1.5.4 series and further, many git commands (not all of them at the
94time of the writing though) come with an enhanced option parser.
95
96Here is an exhaustive list of the facilities provided by this option parser.
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::
105gives a pretty printed usage of the command.
106+
107---------------------------------------------
108$ git describe -h
Junio C Hamanoe74124b2009-09-23 06:51:01109usage: git describe [options] <committish>*
Junio C Hamanof556fc22007-12-23 08:16:38110
111 --contains find the tag that comes after the commit
112 --debug debug search strategy on stderr
113 --all use any ref in .git/refs
114 --tags use any tag in .git/refs/tags
115 --abbrev [<n>] use <n> digits to display SHA-1s
116 --candidates <n> consider <n> most recent tags (default: 10)
117---------------------------------------------
118
119--help-all::
120Some git commands take options that are only used for plumbing or that
121are deprecated, and such options are hidden from the default usage. This
122option gives the full list of options.
123
124
125Negating options
126~~~~~~~~~~~~~~~~
Junio C Hamanoea82cff2009-03-18 01:54:48127Options with long option names can be negated by prefixing `--no-`. For
128example, `git branch` has the option `--track` which is 'on' by default. You
129can use `--no-track` to override that behaviour. The same goes for `--color`
130and `--no-color`.
Junio C Hamanof556fc22007-12-23 08:16:38131
132
133Aggregating short options
134~~~~~~~~~~~~~~~~~~~~~~~~~
135Commands that support the enhanced option parser allow you to aggregate short
Junio C Hamanoea82cff2009-03-18 01:54:48136options. This means that you can for example use `git rm -rf` or
137`git clean -fdx`.
Junio C Hamanof556fc22007-12-23 08:16:38138
139
140Separating argument from the option
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142You can write the mandatory option parameter to an option as a separate
143word on the command line. That means that all the following uses work:
144
145----------------------------
146$ git foo --long-opt=Arg
147$ git foo --long-opt Arg
148$ git foo -oArg
149$ git foo -o Arg
150----------------------------
151
Junio C Hamano4e272312008-01-08 09:13:21152However, this is *NOT* allowed for switches with an optional value, where the
Junio C Hamanof556fc22007-12-23 08:16:38153'sticked' form must be used:
154----------------------------
155$ git describe --abbrev HEAD # correct
156$ git describe --abbrev=10 HEAD # correct
157$ git describe --abbrev 10 HEAD # NOT WHAT YOU MEANT
158----------------------------
159
160
Junio C Hamanofce7c7e2008-07-02 03:06:38161NOTES ON FREQUENTLY CONFUSED OPTIONS
162------------------------------------
163
164Many commands that can work on files in the working tree
165and/or in the index can take `--cached` and/or `--index`
166options. Sometimes people incorrectly think that, because
167the index was originally called cache, these two are
168synonyms. They are *not* -- these two options mean very
169different things.
170
171 * The `--cached` option is used to ask a command that
172 usually works on files in the working tree to *only* work
173 with the index. For example, `git grep`, when used
174 without a commit to specify from which commit to look for
175 strings in, usually works on files in the working tree,
176 but with the `--cached` option, it looks for strings in
177 the index.
178
179 * The `--index` option is used to ask a command that
180 usually works on files in the working tree to *also*
181 affect the index. For example, `git stash apply` usually
182 merges changes recorded in a stash to the working tree,
183 but with the `--index` option, it also merges changes to
184 the index as well.
185
186`git apply` command can be used with `--cached` and
187`--index` (but not at the same time). Usually the command
188only affects the files in the working tree, but with
189`--index`, it patches both the files and their index
190entries, and with `--cached`, it modifies only the index
191entries.
192
193See also http://marc.info/?l=git&m=116563135620359 and
194http://marc.info/?l=git&m=119150393620273 for further
195information.
196
Junio C Hamanof556fc22007-12-23 08:16:38197GIT
198---
Junio C Hamanof7c042d2008-06-06 22:50:53199Part of the linkgit:git[1] suite