git: How do I recursively add all files in a directory subtree that match a glob pattern?

后端 未结 6 1980
谎友^
谎友^ 2021-01-31 14:15

I have several .screen files inside /xxx/documentation and its subdirectories that are already tracked by Git.

After modifying many of these screen files, I

相关标签:
6条回答
  • 2021-01-31 14:20

    git add *.java works for me to add recursively all the java files

    0 讨论(0)
  • 2021-01-31 14:22

    This what I just used for a similar problem of git adding all the files in a directory:

    find . | sed "s/\(.*\)/\"\1\"/g" | xargs git add 
    

    For the original question the command would be:

    find -name "*.screen" | sed "s/\(.*\)/\"\1\"/g" | xargs git add 
    

    Note that I'm dealing with the case where a fully specified file name contains spaces. Thats why my answer. Edit the portion before the first | in order to pick out different files to add.

    0 讨论(0)
  • 2021-01-31 14:23

    I've tried the accepted answer, but it didn't worked for me.. so here's mine just in case someone wants to get it's job done without spending time in dissecting various aspects that might cause the problem:

    find documentation -name "*.screen" | xargs git add -u
    

    //the -u option to git-add adds to index just the files that were previously tracked and modified

    0 讨论(0)
  • 2021-01-31 14:25

    try

    git add ./documentation/*.screen
    
    0 讨论(0)
  • 2021-01-31 14:41

    It's a bug in the documentation. Quote the asterisk with

    $ git add documentation/\*.screen

    or

    $ git add 'documentation/*.screen'

    to get the behavior you want.

    If instead you want to add files in the current directory only, use

    $ git add *.screen

    UPDATE: I submitted a patch that corrects the issue, now fixed as of version 1.6.6.2.

    0 讨论(0)
  • 2021-01-31 14:44

    You told the shell to look for *.screen (i.e. exactly this string - which doesn't exist - instead of what you want "all files that end with .screen). Omit the \\ so the shell can do the file name expansion for you.

    0 讨论(0)
提交回复
热议问题