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
)。
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/