What does “git add -A :/” do?

前端 未结 2 828
青春惊慌失措
青春惊慌失措 2020-12-11 08:01

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?

2条回答
  •  没有蜡笔的小新
    2020-12-11 08:15

    (This answer originally talked about refspecs, which turned out to be irrelevant and incorrect.)

    As lrineau's answer correctly points out, the : character in this case is part of the syntax of a pathspec.

    Documentation on pathspecs is annoyingly difficult to find, but there's a "gitglossary" man page, available either by typing man gitglossary or visiting this web page.

    The relevant part:

    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 ... [snip].

    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.

    The conclusion is the same as in my original answer: :/ refers to the root directory of the current working tree.

提交回复
热议问题