Invalid pathspec magic

When I try to partially generate a file in git, I get the following error message.

git add -p mass_scan.py fatal: Invalid pathspec magic 'prefix:8' in ':(prefix:8)mass_scan.py' No changes. 

What does it mean? How can I partially generate a file?

I am using the git version

 git version 2.6.2.450.g259b5e6 

Installs directly from the source (without the package manager). I can still partially add files using tig .

+7
source share
3 answers

I reinstalled git and the error went away. I don't know what the original problem was, but now it works.

+1
source

There is another case where Invalid pathspec magic may appear: when a file has several attributes declared in .gitattributes .
That is, prior to Git 2.13 (Q2 2017), which fixes this error.

See commit c5af19f , commit b0db704 (March 13, 2017) by Brandon Williams ( mbrandonw ) .
(Combined Junio โ€‹โ€‹C Hamano - gitster - in commit f6c64c6 , March 17, 2017)

pathspec : allow escaped query values

In our own .gitattributes file, we have attributes such as:

 *.[ch] whitespace=indent,trail,space 

When requesting attributes, we want to be able to request the exact value, i.e.

 git ls-files :(attr:whitespace=indent,trail,space) 

should work, but commas are used in attr magic to represent the next attr, so this request is not currently being executed with:

 fatal: Invalid pathspec magic 'trail' in ':(attr:whitespace=indent,trail,space)' 

This change allows you to escape characters with a backslash, so the query

 git ls-files :(attr:whitespace=indent\,trail\,space) 

will match all paths that have the value " indent,trail,space " for the space attribute.


Note: in Git 2.20 (Q4 2018), โ€œ git add ':(attr:foo)' โ€ is not supported and is expected to be rejected while the command line arguments are parsed but not rejected.
Now

See Commit 84d938b (September 18, 2018) Nguyen Tai pclouds Dui ( pclouds ) .
(Combined by Junio โ€‹โ€‹K Hamano - gitster - in faadedb commit , September 24, 2018)

add : do not accept pathspec magic ' attr '

The b0db704 commit ( pathspec : allow attribute request - 2017-03-13, Git v2.13.0-rc0) adds new pathspec magic ' attr ', but only with match_pathspec() .
" git add " has some pathspec-related code that still does not know about " attr " and will help out:

 $ git add ':(attr:foo)' fatal: BUG:dir.c:1584: unsupported magic 40 

A better solution would be to make this support code ' attr '. But I donโ€™t know how much work is needed (I am not familiar with this new magic). In the meantime, let's just reject this magic with a friendlier message:

 $ git add ':(attr:foo)' fatal: :(attr:foo): pathspec magic not supported by this command: 'attr' 

Update t6135 so that the expected error message is t6135 from the "elegant" code rejection path, and not "oops, we should have refused the request to start this magic" path.


And starting with Git 2.21 (Q1 2019), this โ€œpath magicโ€ is no longer reserved for git ls-files , but also applies to git log and git grep !
Traversal of tree objects learned to recognize " :(attr:label) " a path match that was implemented only to enumerate paths in the file system.

See Commit 5a0b97b , Commit 22af33b , Commit 93e2379 , Commit 67022e0 , Commit e092073 (November 18, 2018) from pclouds Thรกi Ngแปc Duy ( pclouds ) .
(Combined Junio โ€‹โ€‹C Hamano - gitster - in commit d6f05a4 , January 14, 2019)

tree-walk : support :(attr) matching

This allows us to use :(attr) with " git grep <tree-ish> " or " git log ".

:(attr) requires another round of verification before we can declare that the path matches. This is done after matching the path, since we have many opportunities for optimization when something does not match.

Please note that if :(attr) present, we can no longer return all_entries_interesting / all_entries_not_interesting , because we cannot be sure of this.
Until match_pathspec_attrs() tells us โ€œyes: all of these paths satisfy :(attr) โ€.

Second note. Even if we go through a specific tree, we use attributes from the working tree (or returning to the index), and not from the .gitattributes files in this tree.
This in itself is not necessarily wrong, but the user just needs to know about it.

+1
source

Try using git add -p or git add filename , but not both at the same time. Gotta help

0
source

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


All Articles