Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

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

like image 700
Amelio Vazquez-Reina Avatar asked Feb 26 '14 16:02

Amelio Vazquez-Reina


2 Answers

As you already know the -A option, let's talk about git add :/ only. According to the documentation of git-add, the last argument is a pathspec. The definition of it is in the documentation of gitglossary. Let me quote the releant parts (I put the important sentences in bold):

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, the leading colon : is followed by a open parenthesis (, a comma-separated list of zero or more "magic words", and a close parentheses ), and the remainder is the pattern to match against the path.

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.

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

You can see that if a pathspec begins by :/ or :(top) then that part of the pathspec is by definition the root of the working tree.

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

like image 166
lrineau Avatar answered Oct 08 '22 20:10

lrineau


(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.

like image 27
Keith Thompson Avatar answered Oct 08 '22 19:10

Keith Thompson