1

Since first learning Git a few months ago, I've been using git add :/ to stage my files before committing, with the impression that the command stages all modified and newly-added files in my Git directory (I assume I got this impression from one of the articles I was using to learn). This has worked fine for me for the past few months, so at least seems to me to behave that way, but from doing some reading around the answers on this site I get the impression that that isn't the case, and the fact that it's such an under-documented command is another hint to this.

What exactly does git add :/ do? If it doesn't stage all modified and newly-added files, is there a command that does, or is this just not (yet) possible with a single command in Git?

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
  • "but from doing some reading around the answers on this site I get the impression that that isn't the case" Please provide links and/or quotes to back up this claim. – Code-Apprentice Nov 12 '19 at 16:59
  • Do you really type ":/" as part of the command? I haven't ever seen or used that particular syntax before. What operating system are you on? – Code-Apprentice Nov 12 '19 at 17:00
  • I guess the under-documentation remark was about the specific syntax `:/` I could swear I remember torek refering to it in some question here, but such string is atrociously hard to research ^^ and I'm busting my head (in vain so far) to find what it was... A reference to the repo root I guess? I'm still unsure. – Romain Valeri Nov 12 '19 at 17:03
  • @Code-Apprentice So you claim the command is in the documentation but seem confused about ':/'? 'git add' is a different command to run from 'git add :/', hence why I'm here asking the question in the first place. – Hashim Aziz Nov 12 '19 at 17:05
  • @Hashim Yes, it took me a while to figure out that ":/" was part of the command. In the title of the question, it looks like an emote. Can you provide some links and quotes to the questions and articles where you read about this command? I'm genuinely interested now because I've never seen this syntax before. – Code-Apprentice Nov 12 '19 at 17:09
  • 4
    Possible duplicate of [What is the meaning of :/ (colon, forward slash) in the 2.0 version of git add --update syntax?](https://stackoverflow.com/questions/21949074/what-is-the-meaning-of-colon-forward-slash-in-the-2-0-version-of-git-add) or [What does “git add -A :/” do?](https://stackoverflow.com/questions/22047909/what-does-git-add-a-do) – Quentin Nov 12 '19 at 17:10
  • 2
    Yes, I misread your question. Now if you can provide some links to give your question more context, we can get past my confusion and I'll be glad to help you. – Code-Apprentice Nov 12 '19 at 17:47
  • @Quentin Thank you, searching both Google and Stack didn't bring up those results for me. – Hashim Aziz Nov 12 '19 at 22:09

1 Answers1

3

See the documentation of pathspec in gitglossary:

pathspec

Pattern used to limit paths in Git commands.

Pathspecs are used on the command line of git ls-files, git ls-tree, git add, git grep, git diff, git checkout, and many other commands to limit the scope of operations to some subset of the tree or worktree. See the documentation of each command for whether paths are relative to the current directory or toplevel. The pathspec syntax is as follows:

  • any path matches itself

  • the pathspec up to the last slash represents a directory prefix. The scope of that pathspec is limited to that subtree.

  • the rest of the pathspec is a pattern for the remainder of the pathname.

    Paths relative to the directory prefix will be matched against that pattern using fnmatch(3); in particular, * and ? can match directory separators.

    For example, Documentation/*.jpg will match all .jpg files in the Documentation subtree, including Documentation/chapter_1/figure_1.jpg.

    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 "magic signature" consists of ASCII symbols that are neither alphanumeric, glob, regex special characters nor colon. The optional colon that terminates the "magic signature" can be omitted if the pattern begins with a character that does not belong to "magic signature" symbol set 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.

    A pathspec with only a colon means "there is no pathspec". This form should not be combined with other pathspec.

    top

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

choroba
  • 231,213
  • 25
  • 204
  • 289