What does the double-dash [--] option do on git reset?

余生颓废 提交于 2019-12-12 07:48:55

问题


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>…]

回答1:


-- 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.




回答2:


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.



来源:https://stackoverflow.com/questions/14217853/what-does-the-double-dash-option-do-on-git-reset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!