Skip to content

Commit d0658ec

Browse files
committed
Document the double-dash "rev -- path" disambiguator
This is a very well established command line convention that old residents of the git mailing list knew by heart and nobody even thought about documenting it explicitly, which was not very nice. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d54467b commit d0658ec

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

Documentation/gitcli.txt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,37 @@ gitcli
1313
DESCRIPTION
1414
-----------
1515

16-
This manual describes best practice in how to use git CLI. Here are
17-
the rules that you should follow when you are scripting git:
16+
This manual describes the convention used throughout git CLI.
17+
18+
Many commands take revisions (most often "commits", but sometimes
19+
"tree-ish", depending on the context and command) and paths as their
20+
arguments. 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,
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
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
33+
`git diff HEAD \--` to ask for the latter.
34+
35+
* Without disambiguating `\--`, git makes a reasonable guess, but errors
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
38+
you have to say either `git diff HEAD \--` or `git diff \-- HEAD` to
39+
disambiguate.
40+
41+
When writing a script that is expected to handle random user-input, it is
42+
a good practice to make it explicit which arguments are which by placing
43+
disambiguating `\--` at appropriate places.
44+
45+
Here are the rules regarding the "flags" that you should follow when you are
46+
scripting git:
1847

1948
* it's preferred to use the non dashed form of git commands, which means that
2049
you should prefer `"git foo"` to `"git-foo"`.
@@ -34,8 +63,8 @@ the rules that you should follow when you are scripting git:
3463
if you happen to have a file called `HEAD` in the work tree.
3564

3665

37-
ENHANCED CLI
38-
------------
66+
ENHANCED OPTION PARSER
67+
----------------------
3968
From the git 1.5.4 series and further, many git commands (not all of them at the
4069
time of the writing though) come with an enhanced option parser.
4170

0 commit comments

Comments
 (0)