What does “--” (double-dash) mean?
git diff [options] [<commit>] [--] [<path>…]
In here, how should I understand what [--] means? And when should I use it.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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 -- *.)
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.