在Git中,“-"(破折号)是什么意思? [英] In Git, what does `--` (dash dash) mean?
问题描述
在阅读Git命令的手册页时,通常会看到一个可选的--
(破折号).以我的经验,--
不是必需的,也没有区别.您什么时候需要它?鉴于它出现在这么多的命令中,这通常意味着什么?
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?
推荐答案
git中的双破折号--
对于不同的命令来说意味着不同的东西,但总的来说,它将选项与参数分开.
The double dash --
in git means different things to different commands, but in general it separates options from parameters.
在 git 中,--
的含义取决于与它一起使用的子命令.它通常将子命令参数(如git checkout
中的分支名称)与修订或文件名分开.有时,它是完全可选的,并且仅用于防止将不寻常的文件名解释为程序选项.
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 being interpreted as program options.
例如
-
git checkout
.要检出提交"(在手册中称为"tree-ish",因为实际上可以指定一系列对象类型),请使用
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>
要将检出仅细化为一个或两个文件,请使用--
将"tree-ish"参数与要检出的文件名"分开.
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
.要提交索引"中的内容(即您通过git add
进行的操作),只需发出git commit
命令.
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消息]
要忽略通过git add
添加的任何内容并在特定文件中提交更改,请使用
git commit -- <filename>
To ignore whatever you have added via git add
and commit the changes in a specific file, use
git commit -- <filename>
git add
.要提交名称以-
或--
开头的文件,必须告诉git add停止读取参数,并开始读取文件名; --
这样做.
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
.要查看仅限于影响文件使用的提交的提交历史记录
git log
. To see the commit history restricted to only commits affecting a file use
git log -- filename
如果需要了解git命令的具体含义,则需要检查手册页.
You need to check the man pages for any git command you use if you need to understand its specific meaning.
这篇关于在Git中,“-"(破折号)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!