Skip to content

Commit

Permalink
Document the double-dash "rev -- path" disambiguator
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jun 27, 2008
1 parent d54467b commit d0658ec
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions Documentation/gitcli.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,37 @@ gitcli
DESCRIPTION
-----------

This manual describes best practice in how to use git CLI. Here are
the rules that you should follow when you are scripting git:
This manual describes the convention used throughout git CLI.

Many commands take revisions (most often "commits", but sometimes
"tree-ish", depending on the context and command) and paths as their
arguments. Here are the rules:

* Revisions come first and then paths.
E.g. in `git diff v1.0 v2.0 arch/x86 include/asm-x86`,
`v1.0` and `v2.0` are revisions and `arch/x86` and `include/asm-x86`
are paths.

* When an argument can be misunderstood as either a revision or a path,
they can be disambiguated by placing `\--` between them.
E.g. `git diff \-- HEAD` is, "I have a file called HEAD in my work
tree. Please show changes between the version I staged in the index
and what I have in the work tree for that file". not "show difference
between the HEAD commit and the work tree as a whole". You can say
`git diff HEAD \--` to ask for the latter.

* Without disambiguating `\--`, git makes a reasonable guess, but errors
out and asking you to disambiguate when ambiguous. E.g. if you have a
file called HEAD in your work tree, `git diff HEAD` is ambiguous, and
you have to say either `git diff HEAD \--` or `git diff \-- HEAD` to
disambiguate.

When writing a script that is expected to handle random user-input, it is
a good practice to make it explicit which arguments are which by placing
disambiguating `\--` at appropriate places.

Here are the rules regarding the "flags" that you should follow when you are
scripting git:

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


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

Expand Down

0 comments on commit d0658ec

Please sign in to comment.