简体   繁体   English

git add./*.java 不起作用?

[英]git add ./*.java doesn't work?

I have a bunch of Java files in my current Java project that I keep modifying and I want to add them all in one fell swoop from the root folder of the project (in Ubuntu).我在当前的 Java 项目中有一堆 Java 文件,我一直在修改这些文件,我想从项目的根文件夹(在 Ubuntu 中)中一次性添加它们。

I tried:我试过:

git add ./*.java

but that doesn't do it.但那不行。 I tried escaping the asterisk like so:我像这样尝试了 escaping 星号:

git add ./\*.java

but that doesn't do it.但那不行。 Then I tried quoting it like so:然后我试着像这样引用它:

git add "./*.java"

but that doesn't do it.但那不行。

The man page for "git add" gives this as an example: “git add”的手册页给出了一个例子:

Adds content from all *.txt files under Documentation directory and its subdirectories:添加文档目录及其子目录下所有 *.txt 文件的内容:

 $ git add Documentation/\*.txt

I tried using a directory such as "Documentation" above to qualify this but that doesn't work either.我尝试使用上面的“文档”等目录来限定它,但这也不起作用。

What am I missing?我错过了什么?

[ Update ] I tried out @GoZoner's suggestion below and it works, but only if the files are new, and not if they are pre-existing ones that have been updated. [更新] 我在下面尝试了 @GoZoner 的建议并且它有效,前提是文件是新的,而不是如果它们是已经更新的预先存在的文件。 This is very odd.这很奇怪。

You need to escape the '.'你需要转义 '.'

git add \./\*.java

works.作品。

$ git add \./\*.c
$ git status
# On branch br1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   bang/boo.c
#   new file:   bing/one.c
#
git add -u *.java

Where在哪里
-u adds modified tracked files -u添加修改后的跟踪文件
*.java is pathspec *.java是路径规范

Instead of doing 'git add' use:而不是做'git add'使用:

git status

That will show you what files are new (unknown by git) and what files have been modified.这将向您显示哪些文件是新文件(git 未知)以及哪些文件已被修改。 More importantly for your case, 'git status' will show the full path to the reported files.对于您的情况更重要的是,“git status”将显示报告文件的完整路径。 Knowing the full path you will be able to add them one-by-one with 'git add full-path-to.java' or, if everything looks committable, 'git add -A' will add them all.知道完整路径后,您将能够使用“git add full-path-to.java”逐一添加它们,或者,如果一切看起来都可提交,则“git add -A”将全部添加。

If you want to limit yourself to files git already knows about, you could combine git-ls-files with a filter:如果你想将自己限制在 git 已知的文件中,你可以将 git-ls-files 与过滤器结合使用:

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

Here you have to specify the path to your folders.在这里您必须指定文件夹的路径。

OR要么

Here you give instruction to show cached c and other o files while excluding standard git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.在这里,您给出的指令是显示缓存的 c和其他o文件,同时排除标准 git 排除项:.git/info/exclude、每个目录中的 .gitignore 以及用户的全局排除文件。

git ls-files -co --exclude-standard | grep '\.java$'| xargs git add

From this answer Recursively add files by pattern .从这个答案Recursively add files by pattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM