git add --update语法的2.0版本中的/(冒号,正斜杠)是什么意思? [英] What is the meaning of :/ (colon, forward slash) in the 2.0 version of git add --update syntax?
问题描述
几个月前我升级了Git,从那时起,我在尝试 git add --update
时收到以下弃用通知:
警告:'git add --update(或-u)'的行为会在树中的子目录中没有路径
参数2.0和
不应再使用。要为整个树添加内容,请运行:
git add --update:/(或git add -u:/)
要限制命令到当前目录,运行:
git add --update。 (或git add -u。)
使用当前的Git版本,该命令仅限于当前的
目录。
警告本身非常有意义,它为我节省了一些重置资源。我习惯了输入。
或:/
,但仍然觉得后者很奇怪,因为它不像任何我遇到的其他命令行语法。 。
是非常令人信服的:它只是表示当前目录,就像 find。
,但:/
...从来没有见过这种情况除外。这是什么意思?
我一直认为它是一个表情符号,当然不是这种情况?
它实际上是现有语法的扩展:这种名称是有效的 gitrevisions 语法很长时间。
以冒号为前缀的名称 1 引用索引内的路径(staging-area),与修订名称后跟冒号和路径引用给定修订中的路径的方式相同: master〜3:foo
是分支 master
前三个版本中文件 foo
的版本。因此:foo
是下一次提交的foo版本。
注意,冒号后面跟着斜线通常用于通过提交日志消息来搜索提交,如gitrevisions中的:/ fix
示例。
这些路径名通常植根于树的顶部(而不是工作树内的任何位置)。例如,如果您的存储库只有两个文件,但名称分别为 README
和 dir / sub.txt
,并且您在 dir
中,仍然写入 master〜3:dir / sub.txt
和 master〜 3:自述
。你可以让git通过强制相对路径名来自动查看 dir /
: git show master〜3:./ sub.txt
和 git show master〜3:../ README
。使用:/ fix
来搜索提交消息,在这里不能使用前导斜杠来表示树的顶部,但由于路径名总是从顶部开始,这是不需要的。
在 如果删除路径名的其余部分,则会得到 1 不总是。 Git对其许多规则的例外通常是明智的,但是却难以解释。 : - ) 2 含义,我不知道为什么。当然,对于非 -colon-prefixed路径是合理的,但对于冒号前缀的路径,为什么? (考虑到一堆现有的代码,它可能更容易实现。) I upgraded Git a couple months ago and since then I've been receiving the following deprecation notice upon attempting Warning: The behavior of 'git add --update (or -u)' with no path
argument from a subdirectory of the tree will change in Git 2.0 and
should not be used anymore. To add content for the whole tree, run: git add --update :/ (or git add -u :/) To restrict the command to the current directory, run: git add --update . (or git add -u .) With the current Git version, the command is restricted to the current
directory. The warning itself makes perfectly good sense, and it's saved me some resetting. I've gotten used to typing the I keep thinking of it as an emoticon, and certainly that's not the case? It's actually an extension of existing syntax: this kind of name has been valid gitrevisions syntax for a long time. A colon-prefixed name generally1 refers to paths within the index (staging-area), in the same way that a revision name followed by a colon and path refer to paths in the given revision: Note, however, that colon followed by slash is generally used to search for commits by their commit log messages, as in the These path names are generally rooted at the top of the tree (rather than wherever you are within your work tree). For instance, if your repository has just two files but they are named In the case of If you drop the rest of the pathname, you get 1Meaning, "not always". Git's exceptions to its many rules are usually sensible, but make for difficult explaining. :-) 2Meaning, "I don't know why". Sure, it makes sense for non-colon-prefixed paths, but for colon-prefixed ones, why? (It probably just was easier to implement, given a bunch of existing code.) 这篇关于git add --update语法的2.0版本中的/(冒号,正斜杠)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!:path
表示在当前树中添加文件。由于一些古怪的原因, 2 与其他git命令不同, git add
即使使用冒号语法也是基于您当前的工作目录工作,所以如果你在 dir /
中,并且你写了 git add:sub.txt
,它会添加 ./sub.txt
。您不能从这里 git add:README
。但是你可以(至少用git 1.8-我不确定这是多久) git add:/ README
,其中
:/
- 确实看起来像一个表情符号!但它指的是存储库顶部的目录。但仅限于 git add
;对于其他git命令,它表示一个提交消息搜索字符串。
git add --update
:
.
or :/
, but still find the latter quite strange because it's unlike any other command line syntax I've encountered. The .
is pretty token: it just means "current directory", like in find .
, but :/
... never seen that except in this context. What does it mean?master~3:foo
is the version of file foo
in branch master
three revisions ago. So :foo
is the version of foo staged for the next commit.:/fix
example in gitrevisions.README
and dir/sub.txt
and you are in dir
, you still write master~3:dir/sub.txt
and master~3:README
. You can get git to look into dir/
automatically by forcing a relative pathname: git show master~3:./sub.txt
and git show master~3:../README
. With :/fix
meaning to search commit messages, leading slash can't be used here to denote the top of the tree, but since the pathnames always start from the top anyway, it's not needed.git add
, though, you can't actually be referring to what is staged now—you're trying to add stuff, to stage it, why would what's staged now matter?—so :path
means to add the file in the current tree. For some wacky reason,2 unlike the rest of the git commands, git add
works based on your current working directory even with the colon syntax, so if you're in dir/
and you write git add :sub.txt
it adds ./sub.txt
. You can't git add :README
from here. But you can (with git 1.8 at least—I'm not sure how long this has been in place) git add :/README
, where the leading slash means "escape the current subdirectory and go to the top of the repository tree instead".:/
—which does indeed look like an emoticon! But it refers to the directory at the top of the repository. But only for git add
; for other git commands, it signifies a commit-message search string.