What is the meaning of: / (colon, slash) in version 2.0 of git add -update?

I updated Git a couple of months ago, and since then I get the following failure notification when I try git add --update :

Warning: the behavior of 'git add -update (or -u)' without a path, the argument from the tree subdirectory will change in Git 2.0 and should no longer be used. To add content for the entire tree, run:

git add -update: / (or Git add -u: /)

To limit the command to the current directory, run:

git add -update. (or Git add -u.)

With the current version of Git, the command is limited to the current directory.

The warning in itself makes sense, and it saved me some reboot. I'm used to typing . or :/ , but still I think the latter is rather strange, because it is not like any other command-line syntax I came across. . is pretty symbolic: it just means "current directory", as in find . but :/ ... never saw this other than this context. What does it mean?

I always think of it as an emoticon, and of course it is not?

+6
source share
4 answers

This is actually an extension of the existing syntax: this kind of name has been valid gitrevisions syntax for a long time.

The designated colon name usually 1 refers to the paths inside the index (staging area), in the same way that the version name followed by the colon and path refers to the paths in this revision: master~3:foo is the version of the foo file in the master branch three versions back. Thus :foo is the version of foo delivered for the next commit.

Note, however, that the colon followed by a slash is usually used to search for commits by commit log messages, as in the example :/fix in gitrevisions.

These path names are typically embedded at the top of the tree (and not wherever you are in the working tree). For example, if your repository has only two files, but they are called 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 automatically search in dir/ by forcing the relative path: git show master~3:./sub.txt and git show master~3:../README . If the value :/fix means searching for fix messages, the leading slash cannot be used here to indicate the top of the tree, but since paths always start at the top, this is not necessary.

In the case of git add , however, you can’t actually refer to what is being put now - you are trying to add material to compose it, why should it be given now? -so :path means add the file to the current tree. For some ridiculous reason 2 , unlike other git commands, git add works based on your current working directory even with a colon syntax, so if you are in dir/ and you write git add :sub.txt by adding ./sub.txt . You cannot git add :README from here. But you can (with git 1.8 at least - I'm not sure how long it has been in place) git add :/README , where the leading slash means "display the current subdirectory and go to the beginning of the repository tree" ,.

If you leave the rest of the path name, you will get :/ , which really looks like an emoticon! But this refers to the directory at the top of the repository. But only for git add ; for other git commands, this means a search string for the commit message.


1 The value is not always. git exceptions to its many rules are usually reasonable, but difficult to explain. :-)

2 Meaning "I do not know why." Of course, this makes sense for paths with a prefix without a colon, but for colon with a prefix, why? (It was probably just easier to implement, given the bunch of existing code.)

+4
source

:/ not the only new syntax, you also have

 :! :(exclude) 

Making 'git log' ignore changes for specific paths

Thus : means that the path is checked immediately. Then you have / , also known as the root directory, or perhaps in this case represents the root of the repository.

+1
source

the first answer is not entirely correct. In the context of git-add :/ cannot be a revision. This is the way. See my answer to the corresponding question β€œ What does” git add -A: / β€œdo? ”.

pathspec is defined in gitglossary (7) .

+1
source

The notation :/ develops in git 2.8 (March 2016) with the notation ' ^{/!-<negative pattern>} :/!-foo

See commit 0769854 (January 31, 2016) and commit 06b6b68 (January 10, 2016) Will be Palmer ( wpalmer ) .
(merger of Junio ​​C Hamano - gitster - on commit fb79532 , February 10, 2016

To name a commit, you can now use the regex :/!-<negative pattern> style, and therefore say

 $ git rev-parse HEAD^{/!-foo} 

and it will return the hash of the first commit available from HEAD, whose commit message does not contain " foo ".
This is the opposite of the existing <rev>^{/<pattern>} syntax.

The specific use case for which this is intended is to perform an operation, excluding the most recent commits containing a specific token.
For example, if you are trying to commit a "work in progress" with messages starting with " WIP " you are working on, then it would be useful to distinguish between the "last commit that was not a WIP commit".
These kinds of things are now possible with commands such as:

 $ git diff @^{/!-^WIP} 

Leader ' /!- ', not just ' /! 'to indicate a negative match, selected to leave room for additional modifiers in the future.

The new git/revisions doc now states:

To match messages starting with a line, you can use, for example. :/^foo '.
Special Sequence ' :/! 'reserved for modifiers to what corresponds to:

  • ' :/!-foo ' does a negative match ,
  • while ' :/!!foo ' matches the literal '!' character followed by 'foo'.
  • Any other sequence starting with ' :/! ', reserved at the moment.
+1
source

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


All Articles