Does git support wildcards in paths?

后端 未结 4 472
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 14:41

I have looked, searched, and read documentation and can\'t really find anything about this.

Basically, I want to be able to do this:

git reset -- *.exe
<         


        
相关标签:
4条回答
  • 2021-02-01 15:36

    To reset all exe files recursively from within a git folder, you can do the following:

    git reset -- \*.exe
    

    Or if you would like to add all java files within a specific sub-folder you can do that too, like this:

    git add ./some/sub/folder/path/**/*.java
    

    where ** means all folders recursively from this point in the path

    0 讨论(0)
  • At least in the case of subfolders/subfiles, there is no need for a wildcard.

    git add .
    

    ...adds the current directory (.) and everything under it. The same goes for...

    git add files/
    

    ...which would add ./files, ./files/foo.txt, and ./files/foo/bar.txt.

    0 讨论(0)
  • 2021-02-01 15:38

    In some cases however, one does need to use wildcards in a specific way to target a specific subset of files and not just all files, especially when working with git rm, or git checkout or git reset. You can achieve the same by simply escaping the wild card character.

    git rm app/assets/javascript/templates/projects/\*.jst.ejs
    
    0 讨论(0)
  • 2021-02-01 15:41

    Git does support some pathspec globbing, but you need to be careful to shell-escape the characters so they aren't interpreted by in your case, msys bash, which doesn't support more sophisticated wildcard expansion.

    EDIT: Also, for your reset example, you can just pass the directory as an argument to git reset and git will operate recursively.

    git reset my/long/path
    

    rather than

    git reset my/long/path/*
    
    0 讨论(0)
提交回复
热议问题