什么是“git add -A:/”做? [英] What does "git add -A :/" do?
问题描述
我看到有同事使用 git add -A:/
来暂存存储库中的文件,但我无法找到文档。我错过了什么?
注意:我明白标记 -A
的含义(这个问题已经在< )。我的问题特别是关于:/
以及它在 git add
中扮演的角色。
:只有/ 。根据 git-add文档,最后一个参数是 pathspec 的。它的定义见 gitglossary的文档。让我引用相关部分(我把重要句子加粗):
以冒号开头的pathspec:has特殊含义。在简短形式中,前面的冒号:后面跟着零个或多个魔术签名字母(可选地以另一个冒号:)结束,其余部分是匹配路径的模式。
在结束魔法签名的可选冒号中,如果模式以不能成为魔术签名且不是冒号的字符开头,则可以省略。长的形式,领先的冒号:后面跟着一个开括号(一个逗号分隔的零个或多个魔术字列表和一个紧密的括号),剩下的就是匹配路径的模式。 p>
魔术签名由一个非字母数字的ASCII符号组成。
top /
即使从内部运行命令,魔术字顶部(助记符:/)也会使模式与工作树的根相匹配一个子目录。
目前只有斜线/被识别为魔法签名,但我们预计在稍后会支持更多类型的魔法你可以看到如果一个 pathspec 是,你可以看到 gins by
:/
或:( :(顶部)
那么 pathspec 的部分是定义工作树的根。
git add:/
p>I have seen colleagues using
git add -A :/
for staging files in repositories, but I am unable to find what that does in the documentation. What am I missing?Note: I understand what the flag
-A
does (this question has been answered in SO before). My question is specifically about:/
and the role it plays ingit add
.解决方案As you already know the
-A
option, let's talk aboutgit add :/
only. According to the documentation of git-add, the last argument is a pathspec. The definition of it is in the documentation of gitglossary. Let me quote the releant parts (I put the important sentences in bold):A pathspec that begins with a colon : has special meaning. In the short form, the leading colon : is followed by zero or more "magic signature" letters (which optionally is terminated by another colon :), and the remainder is the pattern to match against the path. The optional colon that terminates the "magic signature" can be omitted if the pattern begins with a character that cannot be a "magic signature" and is not a colon.
In the long form, the leading colon : is followed by a open parenthesis (, a comma-separated list of zero or more "magic words", and a close parentheses ), and the remainder is the pattern to match against the path.
The "magic signature" consists of an ASCII symbol that is not alphanumeric.
top /
The magic word top (mnemonic: /) makes the pattern match from the root of the working tree, even when you are running the command from inside a subdirectory.
Currently only the slash / is recognized as the "magic signature", but it is envisioned that we will support more types of magic in later versions of git.
You can see that if a pathspec begins by
:/
or:(top)
then that part of the pathspec is by definition the root of the working tree.
git add :/
stages all files in the working tree.这篇关于什么是“git add -A:/”做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!