Git命令-“-"的含义和“-" [英] Git command - significance of "-" and "--"

查看:81
本文介绍了Git命令-“-"的含义和“-"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学习git时,我对何时使用单破折号和双破折号感到困惑.用法有什么显着区别?

When learning git, I'm getting confused with when to use a single dash and double dash. What is the significant difference in the usage?

git ls-tree [-d] [-r] [-t] [-l] [-z] [--name-only] [--name-status] [--full-name] [--full-tree] [--abbrev[=<n>]] <tree-ish> [<path>…]

有时我可以互换使用这些东西.例如:-l--long这让我更加困惑.

Sometimes i can use these interchangeably . ex: -l and --long which confuses me more.

推荐答案

Git与

Git is close to the POSIX Utility Argument Syntax but uses --arg=xx as well (GNU)

本文命令行界面标准" 很好地恢复了所使用的约定:

This document "Standards for Command Line Interfaces" resumes well the convention used:

在原始的Unix传统中,命令行选项是单个字母,后跟单个连字符.
不带以下参数的模式标记选项可以组合在一起;因此,如果-a-b是模式选项,则-ab-ba也是正确的,并且两者都启用. 选项的参数(如果有的话)紧随其后(可选地由空格分隔).
在这种样式中,小写的选项比大写的要好.使用大写选项时,将它们作为小写选项的特殊变体是一种很好的形式.

In the original Unix tradition, command-line options are single letters preceded by a single hyphen.
Mode-flag options that do not take following arguments can be ganged together; thus, if -a and -b are mode options, -ab or -ba is also correct and enables both.
The argument to an option, if any, follows it (optionally separated by whitespace).
In this style, lowercase options are preferred to uppercase. When you use uppercase options, it's good form for them to be special variants of the lowercase option.

最初的Unix风格是在缓慢的ASR-33电传打字机上发展起来的,这种打字机使简洁成为一种美德.因此是单字母选项.
按住Shift键需要实际的努力;因此偏好使用小写字母,并使用"-"(而不是逻辑上更多的"+")来启用选项.

The original Unix style evolved on slow ASR-33 teletypes that made terseness a virtue; thus the single-letter options.
Holding down the shift key required actual effort; thus the preference for lower case, and the use of "-" (rather than the perhaps more logical "+") to enable options.

GNU样式使用以两个连字符开头的选项关键字(而不是关键字字母).几年后,当某些相当复杂的GNU实用程序开始用完单字母选项键时,情况就发生了变化(这是症状的补丁,而不是潜在疾病的治疗方法).
它之所以受欢迎,是因为GNU选项比旧样式的字母汤更易于阅读.
如果不分隔空格,则GNU样式的选项无法组合在一起.选项参数(如果有)可以用空格或单个"="(等号)字符分隔.

The GNU style uses option keywords (rather than keyword letters) preceded by two hyphens. It evolved years later when some of the rather elaborate GNU utilities began to run out of single-letter option keys (this constituted a patch for the symptom, not a cure for the underlying disease).
It remains popular because GNU options are easier to read than the alphabet soup of older styles.
GNU-style options cannot be ganged together without separating whitespace. An option argument (if any) can be separated by either whitespace or a single "=" (equal sign) character.

选择了GNU双连字符选项首选项,以便可以在同一命令行上明确混合使用传统的单字母选项和GNU样式的关键字选项.
因此,如果您的初始设计只有很少且简单的选项,那么您可以使用Unix样式,而不必担心如果以后需要切换到GNU样式时会导致不兼容的卖旗日".
另一方面,如果您使用的是GNU样式,则最好至少在最常用的选项上支持单字母等效项.

The GNU double-hyphen option leader was chosen so that traditional single-letter options and GNU-style keyword options could be unambiguously mixed on the same command line.
Thus, if your initial design has few and simple options, you can use the Unix style without worrying about causing an incompatible ‘flag day’ if you need to switch to GNU style later on.
On the other hand, if you are using the GNU style, it is good practice to support single-letter equivalents for at least the most common options.

这篇关于Git命令-“-"的含义和“-"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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