Search code examples
gitsyntax

In git, what does `--` (dash dash) mean?


When reading the man pages for Git commands, you will often see an optional -- (dash dash). In my experience, the -- is not necessary and makes no difference. When do you need it? What does it mean in general, given that it appears in so many commands?


Solution

  • The double dash -- in git means different things to different commands, but in general it separates options from parameters.

    In git specifically, the meaning of -- depends on which subcommand you are using it with. It usually separates subcommand arguments (like the branch name in git checkout) from revisions or filenames. Sometimes it is completely optional and used only to prevent an unusual filename from being interpreted as program options.

    For Example

    • git checkout. To check out a "commit" (referred to as "tree-ish" in the manual, because you can actually specify a range of object types) you use

      git checkout <commit>

      To refine the checkout to just a file or two, use -- to separate the "tree-ish" parameters from the "filenames" you wish to check out.

    • git commit. To commit whatever is in the "index" (ie, what you have staged via git add, simply issue the git commit command.

      git commit [-m message]

      To ignore whatever you have added via git add and commit the changes in a specific file, use git commit -- <filename>

    • git add. To commit a file whose name begins with a - or a --, you must tell git add to stop reading parameters, and start reading filenames; -- does that.

      git add -- -sample.txt

    • git log. To see the commit history restricted to only commits affecting a file use

      git log -- <filename>

    You need to check the man pages for any git command you use if you need to understand its specific meaning.