What does git add -A: / "do do?

I saw colleagues using git add -A :/ to put files in repositories, but I can't find what the documentation does. What am I missing?

Note I understand what the -A flag does (SO was answered to this question). My question is specifically about :/ and the role it plays in git add .

+4
source share
3 answers

As you already know the -A option, only talk about git add :/ . According to the git-add documentation , the last argument is the path. Its definition is in the gitglossary documentation . Let me quote the highlighted parts (I put important sentences in bold):

A path starting with a colon: is of particular importance. In a short form, leading a colon: followed by zero or more letters of the "magic signature" (which does not necessarily end with another colon :), and the remainder is a template that will correspond to the path. An optional colon that completes the magic signature may be omitted if the pattern begins with a character that cannot be a magic signature and is not a colon.

In a long form, a leading colon: it is followed by an open bracket (a section with zeros or more “magic words”, separated by commas, and closed parentheses), and the rest is a pattern corresponding to the path.

A “magic signature” consists of an ASCII character that is not alphanumeric.

top /

The magic word top (mnemonics: /) makes the pattern match the root of the working tree, even when you run the command from within the subdirectory.

Currently, only a slash / is recognized as a "magic signature", but it is assumed that we will support more types of magic in later versions of git.

You can see that if pathspec starts with :/ or :(top) , then this part of pathspec is by definition the root of the working tree.

git add :/ processes all files in the working tree.

+2
source

(This answer originally spoke of refspecs, which turned out to be inconsequential and incorrect.)

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

The documentation for pathspecs is annoyingly hard to find, but there is a gitglossary man page, available either by entering man gitglossary or by visiting this web page .

Relevant Part:

The pathspec property starting with a colon : has special meaning. in short form, in the leading colon : should be zero or more “signature magic” (which optionally ends with another colon :), and the remainder is a template that will match the path. an optional colon that completes the magic signature may be omitted if the pattern begins with a character that cannot be a magic signature and is not a colon.

In long form ... [snip].

A “magic signature” consists of an ASCII character that is not alphanumeric.

top /
The magic word top (mnemonics: / ) makes the pattern matching the root of the working tree, even when you execute the command from within the subdirectory.

The output is similar to my original answer:: :/ refers to the root directory of the current working tree.

+3
source

From my guide:

  -A, --all Like -u, but match <filepattern> against files in the working tree in addition to the index. That means that it will find new files as well as staging modified content and removing files that are no longer in the working tree. 
0
source

Source: https://habr.com/ru/post/947734/


All Articles