java - 忽略 Git 中的 .classpath 和 .project

标签 java eclipse git gitignore

I keep myself telling me and others not to commit .classpath and .project files and use Maven.

不知何故,初级开发人员总是忽略某些规则并提交这些文件,对于可以快速开始使用代码的新手来说,拥有这些文件会更好。

现在,我想尝试/做点什么。当我克隆 repo 时,我会得到 .classpath 和 .project 文件,当然它们会在我的系统中被修改。

But I want them not to be committed and should always be ignored while synchronizing with Git. So that my changes in local system doesn't mess up with Git and Git changes of those files doesn't mess up my local files.

我如何实现这一目标?无论如何要以这种方式将那些文件标记为被忽略?

最佳答案

如果 .project.classpath 已经提交,那么它们需要从索引中删除(但不是磁盘)

git rm --cached .project
git rm --cached .classpath

然后 .gitignore 将起作用(并且可以通过克隆添加和共享该文件)。
例如,这个 gitignore.io/api/eclipse然后文件将起作用,其中包括:

# Eclipse Core      
.project

# JDT-specific (Eclipse Java Development Tools)     
.classpath

请注意,您可以在克隆时使用“Template Directory”(确保您的用户将环境变量 $GIT_TEMPLATE_DIR 设置为所有人都可以访问的共享文件夹)。
该模板文件夹可以包含 info/exclude 文件,带有 ignore rules您希望对 所有 存储库强制执行,包括任何用户都会使用的新存储库 (git init)。


作为 commentedAbdollah

When you change the index, you need to commit the change and push it.
Then the file is removed from the repository. So the newbies cannot checkout the files .classpath and .project from the repo.

关于java - 忽略 Git 中的 .classpath 和 .project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18955149/

相关文章:

java - 将 RGB 转换为位图中的 X 和 Y

java - JBoss EAP 6 上的 OSGi

java - 通过 Web 服务将文件从 java 发送到 .net

java - 无限启动应用程序android Eclipse

java - 将 Jogl 文档添加到用户库

java - 当我三次单击 JTree 节点时,为什么文本未被选中或不可编辑?

eclipse - eclipse pydev 中的 anaconda opencv Unresolved 导入

Git 注释在 `git clone --mirror` 之后丢失

git - 在 Visual Studio 2013 中禁用 git

git - 如何使用 GitHub V3 API 获取 repo 的提交计数?