按模式递归添加文件 [英] Recursively add files by pattern

查看:126
本文介绍了按模式递归添加文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,我想添加 A / B / C / foo.java D / E / F / bar.java (和其他几个java文件) :

  git add'* .java'

不幸的是,这并没有按预期的那样工作。

如果某些要添加的文件可能尚未被追踪,可能是您最好的选择。如果你想限制自己已经知道的文件,你可以结合使用 git-ls-files 和一个过滤器:

  git ls-files [path] | grep'\.java $'| xargs git add 

Git本身并不提供任何花哨的机制,因为它基本上是一个shell问题:你如何得到一个文件列表作为给定命令的参数。


How do I recursively add files by a pattern (or glob) located in different directories?

For example, I'd like to add A/B/C/foo.java and D/E/F/bar.java (and several other java files) with one command:

git add '*.java'

Unfortunately, that doesn't work as expected.

解决方案

Sergio Acosta's answer is probably your best bet if some of the files to be added may not already be tracked. If you want to limit yourself to files git already knows about, you could combine git-ls-files with a filter:

git ls-files [path] | grep '\.java$' | xargs git add

Git doesn't provide any fancy mechanisms for doing this itself, as it's basically a shell problem: how do you get a list of files to provide as arguments to a given command.

这篇关于按模式递归添加文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆