如何不在 git 中显示 .class
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14251253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How not to display the .class in git
提问by Rodel Sarate
I don't want to display .class
files when executing git status
.
我不想.class
在执行时显示文件git status
。
I created a file named .gitignore
and entered the .class
in the file but nothing happened.
我创建了一个名为 的文件.gitignore
并.class
在文件中输入,但没有任何反应。
What is the best way to prevent the .class
file from being displayed when you execute git status
command?
.class
执行git status
命令时防止文件显示的最佳方法是什么?
回答by VonC
Make sure your .class files were not alreadyadded to the index.
You would need to git rm -r --cached path/to/.classfiles/
those files first.
(they will still be on the disk, but no longer part of the git index, and will be ignored by the git status
)
确保您的 .class 文件尚未添加到索引中。
您首先需要git rm -r --cached path/to/.classfiles/
这些文件。
(它们仍将在磁盘上,但不再是 git 索引的一部分,并且会被 忽略git status
)
If you don't want any .class
file versioned (but you didn't include them in the .gitignore
initially), as Michal Stefanowcommentsbelow:
如果您不希望任何.class
文件版本化(但您最初没有将它们包含在内.gitignore
),正如Michal Stefanow在下面评论的那样:
git rm -r --cached *.class
回答by Amber
You probably actually want to add *.class
into your .gitignore
file, not .class
- the former will match any class file (because of the wildcard *
), whereas the latter only matches a file named exactly .class
.
您可能实际上想要添加*.class
到您的.gitignore
文件中,而不是.class
- 前者将匹配任何类文件(因为通配符*
),而后者只匹配名为.class
.
回答by KayV
Create a new file named ./gitignore in your directory and add the following lines in that:
在您的目录中创建一个名为 ./gitignore 的新文件,并在其中添加以下几行:
target/
bin/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
target/