Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

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.

2 Answers

up vote 7 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
add comment

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
2  
+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
add comment

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