使用git,我该如何执行git add,并仍然忽略.gitignore中的模式? [英] With git, how can I perform a git add and still have it ignore the patterns in .gitignore?

查看:827
本文介绍了使用git,我该如何执行git add,并仍然忽略.gitignore中的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些类似于 git add * .java 的东西,不要因为其中一个文件与.gitignore匹配而抛出。

I want to do something like git add *.java and not let it throw up just because one of those files matched the .gitignore.

例如:
在我的目录中,我有

For example: In my directory I have

ignored.java
something.java
somethingelse.java 
somethingevenmoreelse.java.

最后三个文件是由我创建的。然后我想要做 git add * .java

where the three last files were just created by me. I then want to do git add *.java

并且让它添加这三个文件。换句话说,不要给我

and have it add those three files. In other words, instead of giving me

The following paths are ignored by one of your .gitignore files:
ignored.java
Use -f if you really want to add them.
fatal: no files added

...我宁愿忽略它。 gitignored文件并添加其余部分。

... I would rather it would just ignore the .gitignored files and add the rest.

推荐答案

如果引用glob模式,那么它将被git而不是shell解释

If you quote the glob pattern then it will interpreted by git instead of the shell and it will ignore the ignored files before adding the rest without error.

git add '*.java'

或者:

alternatively:

git add \*.java

这篇关于使用git,我该如何执行git add,并仍然忽略.gitignore中的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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