把它放在单引号周围。这应该有效。
git add '*s.rb'
更新
经过更多的测试,我发现我什至可以git add *s.rb不用引号。这可能只适用于我的 git 版本 1.7.10.4(Mac OSX Lion,自制软件)。我的解释是,如果 shell 通配符扩展不匹配任何文件,它会将原始未扩展参数 '*s.rb' 提供给git add.
sh-3.2$ git status
#
# modified: config/routes.rb
# modified: spec/models/products_spec.rb
#
现在我git add没有引号。
sh-3.2$ git add *s.rb
令人惊讶的是它的工作原理!
sh-3.2$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: config/routes.rb
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: spec/models/products_spec.rb
#
如果通配符模式不匹配任何文件,git 会给出这个错误。
sh-3.2$ git add *x.rb
fatal: pathspec '*x.rb' did not match any files