且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Git中,“-"(破折号)是什么意思?

更新时间:2022-04-28 04:54:30

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.