Possible Duplicate:
What does “--” (double-dash) mean?

git diff [options] [<commit>] [--] [<path>…]

In here, how should I understand what [--] means? And when should I use it.

marked as duplicate by l0b0, manatwork, daisy, Renan, rahmu Oct 18 '12 at 13:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


As always, you should read a command's manpage to find out how it interprets its arguments.

-- is commonly used to indicate the end of the command options. This is especially useful if you want to pass a filename or other argument that begins with -. It's also a good idea to use it before wildcards that might expand to a filename beginning with a hyphen. (For example, try mkdir foo; cd foo; echo >-l; ls *; ls -- *.)

But git diff also uses it to indicate whether an argument is a <commit> (indicating what revision to diff) or a <path> (indicating which file to diff). It can usually guess, but it's possible for a value to be both a valid commit and a valid path. In that case, you can use git diff foo -- to indicate that foo is a commit, or git diff -- foo to indicate that foo is a path.


The -- is commonly used in command to indicate the end of options. This is useful if your filename begins with a "-" or your input is unknown. Here is an example of its use:

git diff --stat -- --file1 --file2

--file1 is treated as a filename rather than another option.

  • 3
    +1 for commonly. Do note however that many utilities will work just as well with the file specified as ./--file1 etc. – a CVn Oct 18 '12 at 8:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.