“git add” using wildcard is not functioning as I hoped - must I cd into specific directories?

后端 未结 3 2088
粉色の甜心
粉色の甜心 2020-12-24 10:58

When I try to do a basic git add *.erb (or any simple wildcard expressions) git is not recognizing it (them). As a side-note, I have never done this before so I

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 11:17

    Put it around single quotes. This should work.

    git add '*s.rb'

    UPDATE

    After more testing, I find out that I can even do git add *s.rb without quotes. This might just work for me with my git version 1.7.10.4 (Mac OSX Lion, homebrew). My explanation is that if shell wildcards expansion doesn't match any file, it'd supply the original unexpanded argument '*s.rb' to git add.

    sh-3.2$ git status
    #
    #   modified:   config/routes.rb
    #   modified:   spec/models/products_spec.rb
    #
    

    Now I do git add without quotes.

    sh-3.2$ git add *s.rb
    

    Surprisingly it works!

    sh-3.2$ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD ..." to unstage)
    #
    #   modified:   config/routes.rb
    #
    # Changes not staged for commit:
    #   (use "git add ..." to update what will be committed)
    #   (use "git checkout -- ..." to discard changes in working directory)
    #
    #   modified:   spec/models/products_spec.rb
    #
    

    If wildcard pattern doesn't match any file, git will give out this error.

    sh-3.2$ git add *x.rb
    fatal: pathspec '*x.rb' did not match any files
    

提交回复
热议问题