对于一个 netbeans java 项目,.gitignore 文件中应该包含什么内容?

在 netbeans 中,java 项目的. gitignore 文件的内容应该是什么?

57747 次浏览

There are a fair number of files that you probably do not need to commit into git, since they are built, are generated by NB or contain environment specific information.

If you create a project that uses Ant as the build mechanism, you usually end up with a directory tree that looks like this...

project-root-directory/
+ nbproject/
build-impl.xml
+ private/
+ project.properties
+ project.xml
+ src/
+ test/
+ build.xml

After you do a build.. there will be a couple additional directories

project-root-directory/
+ build/
+ dist/
+ nbproject/
build-impl.xml
+ private/
+ project.properties
+ project.xml
+ src/
+ test/
+ build.xml

You should probably put the build, dist and nbproject/private directories (and their children) into your .gitignore.

If you want to be very aggressive about excluding files, you may want to consider excluding all the files that appear in nbproject EXCEPT project.properties and project.xml. The other files in the nbproject directory are regenerated by NetBeans when the project is opened.

There should be no NetBeans-specific files in your .gitignore. The .gitignore file is project-specific but shared between developers, IOW there should only be things in there that are common for all developers working with the code (including ones that use OSX, Linux instead of Windows and Eclipse, IntelliJ or Notepad as editors) and that are specific to the project.

If there are some files that you would like to ignore based on your specific environment (like e.g. Windows Thumbs.db and desktop files or NeBeans nbproject directories) you should do that in your global ignore list, not in the project-specific .gitignore – if only because then you don't need to add them to every single of your projects individually.

If the files you want to ignore are both specific to your environment and specific to the project, put them into that repository's .git/info/exclude.

# NetBeans specific #
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml


# Class Files #
*.class


# Package Files #
*.jar
*.war
*.ear