14

I've seen commands like:

git reset e542 -- readme.txt

I understand this command puts in the index the contents of the file readme.txt from commit e542. But what's the -- option doing there?

The git reset man page lists it as optional for the first two forms but I couldn't find what it means.

git reset [-q] [<commit>] [--] <paths>…
git reset (--patch | -p) [<commit>] [--] [<paths>…]
AngraX
  • 1,773
  • 2
  • 17
  • 30
  • 2
    On a sidenote: You'll find this ``--`` syntax on many other command line tools, see ``rm``, ``cp``, ``chmod``, … – Jonas Schäfer Jan 08 '13 at 15:13
  • 2
    See http://stackoverflow.com/questions/1192180/deleting-a-badly-named-git-branch/1192194#1192194 – VonC Jan 08 '13 at 15:50
  • @VonC - Thanks. Hard to find if you do not know what to look for. – AngraX Jan 08 '13 at 21:16
  • possible duplicate of [Meaning of Git checkout double dashes](http://stackoverflow.com/questions/13321458/meaning-of-git-checkout-double-dashes) – random May 23 '14 at 12:32
  • @random since this question is in the context of `reset` instead of `checkout`, arguing that it's a duplicate is a hard sell. Maybe we just need to make a canonical question for this type of thing for Git, like "What does a double-dash followed by a path mean in Git?". –  May 23 '14 at 20:40
  • See also [What does “--” (double-dash) mean? (also known as “bare double dash”)](http://unix.stackexchange.com/q/11376/8132). –  May 23 '14 at 20:40
  • In the context of Git and `--` checkout and reset matter less than the double dashes. But looks eventually answered here as well http://stackoverflow.com/questions/2530060/can-you-explain-what-git-reset-does-in-plain-english/ @cup – random May 23 '14 at 23:09

2 Answers2

21

-- separates branch names from file names, in case there is any ambiguity (if you have a branch and a file with the same name). If there are no ambiguities, you don't need the --.

Also as mentioned by Jonas Wielicki, this allows for file names that start with a -; these would otherwise be interpreted as command-line options.

Anders Johansson
  • 3,706
  • 16
  • 18
0

I believe it just separates the commit (which is an optional parameter) from the list of paths. If you didn't have the separator there'd be no sure fire way to distinguish if the first parameter was a path or a commit.

Andy
  • 4,768
  • 3
  • 24
  • 36
  • Somewhat incorrect. Git pretty well can do that. Commits are either branch names or commit ids or other kinds of references, all of which can be easily checked (commit ids are hexvalues, other kinds of references can be found in certain directories under ``.git``). So there is *a* way to distinguish the first parameter from a path if its meant to be a commit, but _only_ if its unambigous. – Jonas Schäfer Jan 08 '13 at 15:11
  • That's what I meant, but my answer didn't properly capture that. – Andy Jan 09 '13 at 18:19