在Git中, - (短划线)是什么意思? [英] In Git, what does -- (dash dash) mean?

查看:187
本文介绍了在Git中, - (短划线)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读Git命令的手册页时,您经常会看到一个可选的 - (破折号)。根据我的经验, - 没有必要,并没有什么区别。你什么时候需要它?一般情况下,这是什么意思,因为它出现在如此多的命令中?

双击破折号 - in git对不同的命令意味着不同的东西,但通常它将选项与参数分开。



git 中,具体来说, - 取决于您正在使用哪个子命令。它通常将子命令参数(如git checkout中的分支名称)与修订或文件名分开。有时它是完全可选的,并且仅用于防止将不寻常的文件名解释为程序选项。



例如


  • git结帐。要检出commit(在手册中称为tree-ish,因为实际上可以指定一系列对象类型),您可以使用

    git checkout 提交



    要将结帐优化为一两个文件,请使用 - 来分隔 -ish参数。


  • git commit。要提交索引中的任何内容(例如,通过 git add 执行的操作,只需简单地发出git commit命令。



    git提交[-m message]



    要忽略通过 git add 添加的任何内容并在特定文件中提交更改,请使用
    git commit - filename


  • git add。要提交以' - '或' - '开头的文件,必须告诉git add停止阅读参数,并开始读取文件名。' - '就是这样。



    git add - -myfile




如果你需要了解它的具体含义,你需要检查你使用的任何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?

解决方案

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

In git specifically, the -- depends on which subcommand you are using. 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 unusual filename 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 the -- 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, simple 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 beginning with a '-' or a '--', you must tell git add to stop reading parameters, and start reading filenames. The '--' does that.

    git add -- -myfile

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

这篇关于在Git中, - (短划线)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆