git:如何递归添加目录子树中与 glob 模式匹配的所有文件?
我在 /xxx/documentation
及其子目录中有几个 .screen 文件,这些文件已被 Git 跟踪。
修改许多这样的屏幕文件后,我运行 git add Documentation/\\*.screen ,如 git-add 文档中的第一个示例所示,以进行暂存这些文件,但命令失败:
fatal: pathspec 'documentation/\*.screen' did not match any files
是我的命令错误,还是 git 有错误?
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 run git add documentation/\\*.screen
—as indicated by the first example in git-add
's documentation—to stage these files, but the command fails:
fatal: pathspec 'documentation/\*.screen' did not match any files
Is my command bad, or does git have a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是文档中的一个错误。 引用星号
用或
以获得您想要的行为。
如果您只想在当前目录中添加文件,请使用
更新:我提交了修正了该问题的补丁,现已修复 自版本 1.6.6.2 起。
It's a bug in the documentation. Quote the asterisk with
or
to get the behavior you want.
If instead you want to add files in the current directory only, use
UPDATE: I submitted a patch that corrects the issue, now fixed as of version 1.6.6.2.
我已经尝试了接受的答案,但它对我不起作用..所以这是我的,以防万一有人想要完成它的工作而不花时间剖析可能导致问题的各个方面:
//the -u 选项git-add 仅将之前跟踪和修改的文件添加到索引
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:
//the -u option to git-add adds to index just the files that were previously tracked and modified
您告诉 shell 查找
*.screen
(即正是这个字符串 - 它不存在 - 而不是您想要的“以.screen
结尾的所有文件)省略\\
以便 shell 可以为您进行文件名扩展。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.这就是我刚刚用于解决 git 添加目录中所有文件的类似问题的方法:
对于最初的问题,命令是:
请注意,我正在处理完全指定的文件名包含空格的情况。这就是我的回答的原因。编辑第一个
|
之前的部分,以便选择要添加的不同文件。This what I just used for a similar problem of git adding all the files in a directory:
For the original question the command would be:
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.git add *.java 适合我递归添加所有 java 文件
git add *.java works for me to add recursively all the java files
尝试
try