Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

marked as duplicate by l0b0, manatwork, warl0ck, 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.

up vote 11 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
ohhhh. thank you. – Benjamin Oct 18 '12 at 7:39
+1 for commonly. Do note however that many utilities will work just as well with the file specified as ./--file1 etc. – Michael Kjörling Oct 18 '12 at 8:27

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