如何不在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:14:05  来源:igfitidea点击:

How not to display the .class in git

gitgitignoregit-status

提问by Rodel Sarate

I don't want to display .classfiles when executing git status.

我不想.class在执行时显示文件git status

I created a file named .gitignoreand entered the .classin the file but nothing happened.

我创建了一个名为 的文件.gitignore.class在文件中输入,但没有任何反应。

What is the best way to prevent the .classfile from being displayed when you execute git statuscommand?

.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 .classfile versioned (but you didn't include them in the .gitignoreinitially), as Michal Stefanowcommentsbelow:

如果您不希望任何.class文件版本化(但您最初没有将它们包含在内.gitignore),正如Michal Stefanow在下面评论的那样:

git rm -r --cached *.class

回答by Amber

You probably actually want to add *.classinto your .gitignorefile, 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/