git add -A:/关于Git 2.X和与pathspec的关系 [英] git add -A :/ on Git 2.X and relationship with pathspec
问题描述
我已阅读几个地方表示 git add -A
已经改变了一段时间了。
从2.x(例如Git 2.5.0)开始, git add -A:/
究竟是干什么用的?我在:或:/
选项.com / docs / git-addrel =nofollow noreferrer>文档。它是 pathspec
?怎么会这样?文档提供的示例仅显示glob模式(例如 *。c
)或简单路径规范(例如 dir
)以添加任何在 dir
之下的任何东西)。
因为git 2.0, git add -A
和 git add -A:/
是相同的。
但是魔法pathspec :/
不是新的,可以从git 1.7.6(2011年4月)回来。请参阅提交8a42c98 。它记录在 文档中/glossary-content.txt
一个以冒号<$ c $开头的pathspec c>:具有特殊含义。
在简短形式中,前面的冒号:
后面跟着零个或多个神奇的
签名字母(可选地由另一个冒号:
),
结尾,其余部分是匹配路径的模式。 p>
:top:or:/
魔术字
顶部
(魔法签名:/
)使模式与工作树的根匹配,即使您在子目录内运行命令。
请注意,如果您想添加一个名为'
:/
'(git add -A:/
),只有在git 2.7(Nov 2015)
才有可能。 commit 29abb33 (2015年10月25日)作者: Junio C Hamano(gitster
)。
由于Git 2.0,
add -u
和add -A
从没有任何pathspec的子目录运行意味着工作树中的所有内容(2.0之前,它们被限制在当前目录中)。
限制到当前目录是通过在命令行中插入。
来实现的,当最终用户没有给我们任何pathspec时。
在2.0时,我们更新代码以插入:/
(而不是'。
')来考虑顶级的所有内容,通过使用pathspec魔术top
。
需要更长的时间,并且在所述提交29abb33中修复:
git add -A
不再使用:/
即将到来的git 2.7)
顺便说一下,这样的简化还修复了一个小例子错误,即
源于:/
并不一定意味着任何魔法。
当用户有一个目录'时,用户会在命令行中输入
git --literal-pathspecs add -u:/
:$ (她知道她的:/
将被视为'太阳下的所有魔法路径规格',除非她禁用魔法与- literal-pathspecs
)。
$ b内部使用'
:/
'的行为方式与显式给出的:/当使用--literal-pathspecs运行时,不会在代码中添加所有东西。
内部使用
:/
不再是,git --literal-pathspecs add -u:/ 实际上可以工作,并在名为column(' :
')的文件夹下添加文件。I have read in several places that the behavior of
git add -A
has changed a bit over time.As of 2.x (e.g. Git 2.5.0), what does
git add -A :/
exactly do? I couldn't find the option:
or:/
in the documentation. Is it apathspec
? How so? The examples the documentation provides only show glob patterns (e.g.*.c
) or simple path specifications (e.g.dir
to add anything underdir
).解决方案Since git 2.0,
git add -A
andgit add -A :/
are the same.
But the magic pathspec:/
is not new and dates back from git 1.7.6 (Apr 2011). See commit 8a42c98. It is documented inDocumentation/glossary-content.txt
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.
:top: or :/
The magic word
top
(magic signature:/
) makes the pattern match from the root of the working tree, even when you are running the command from inside a sub-directory.
Note that if you want to add a folder named '
:/
' (git add -A :/
), this will be possible only in git 2.7 (Nov 2015)
See commit 29abb33 (25 Oct 2015) by Junio C Hamano (gitster
).Since Git 2.0, "
add -u
" and "add -A
" run from a subdirectory without any pathspec mean "everything in the working tree" (before 2.0, they were limited to the current directory).
The limiting to the current directory was implemented by inserting ".
" to the command line when the end user did not give us any pathspec.
At 2.0, we updated the code to insert ":/
" (instead of '.
') to consider everything from the top-level, by using a pathspec magic "top
".(This is no longer needed, and fixed in said commit 29abb33: the implementation of
git add -A
no longer use:/
for the upcoming git 2.7)Incidentally such a simplification also fixes a corner case bug that stems from the fact that "
:/
" does not necessarily mean any magic.
A user would say "git --literal-pathspecs add -u :/
" from the command line when she has a directory ':
' and wants to add everything in it (and she knows that her:/
will be taken as 'everything under the sun' magic pathspec unless she disables the magic with--literal-pathspecs
).The internal use of '
:/
' would behave the same way as such an explicitly given ":/" when run with "--literal-pathspecs", and will not add everything under the sun as the code originally intended.Since that internal use of
:/
is no more, agit --literal-pathspecs add -u :/
will actually work, and add files under the folder named "column" (':
').这篇关于git add -A:/关于Git 2.X和与pathspec的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!