我已阅读 several places git add -A
has changed 的行为随着时间的推移。
从 2.x 开始(例如 Git 2.5.0),git add -A :/
到底做了什么?我在 the documentation 中找不到选项 :
或 :/
.它是 pathspec
吗?为何如此?文档提供的示例仅显示 glob 模式(例如 *.c
)或简单的路径规范(例如 dir
以在 dir
下添加任何内容)。
最佳答案
从 git 2.0 开始,git add -A
和 git add -A :/
是一样的。
但是神奇的路径规范 :/
并不是新的,可以追溯到 git 1.7.6(2011 年 4 月)。参见 commit 8a42c98 .它记录在 Documentation/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.
请注意,如果您想添加名为“:/
”的文件夹(git add -A :/
),这仅在 git 2.7(11 月2015)
参见 commit 29abb33 (2015 年 10 月 25 日)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
".
(这不再需要,并在所述提交 29abb33 中修复:git add -A
的实现不再使用 :/
用于即将到来的 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.
由于内部不再使用 :/
, git --literal-pathspecs add -u :/
将实际工作,并在文件夹下添加文件命名为“列”(':
')。
关于git add -A :/on Git 2. X 和 pathspec 的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31951595/