如何在“工作区”安全地使用 git与分支和.metadata 的级别?
我在工作区级别有一个 git 存储库。即一个存储库中的多个密切相关的 Eclipse 项目。
如果我将 .metadata 添加到 .gitignore,那么每次创建新分支并签出时,我都会丢失 .metadata 文件,因此手动导入所有项目。这很不愉快。
在版本控制下存储 .metadata 文件是否安全?这是一个多开发人员项目,JDK 版本甚至操作系统(将来)可能会有所不同。 (目前我们都使用 Ubuntu。)
还有其他不应提交的 IDE 文件吗?
谢谢,
克里斯。
I have a git repo at the workspace level. i.e. multiple closely related Eclipse projects in one repo.
If I add .metadata to .gitignore then each time I create new branch and checkout I loose my .metadata file and therefore import all the projects manually. This is unpleasant.
Is it safe to store the .metadata file under version control? This is a multi-developer project and JDK versions and perhaps even OSs (in future) may vary. (We're all on Ubuntu at present.)
Are there any other IDE files which shouldn't be comitted?
Thanks,
Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,在将文件和/或目录添加到
.gitignore
之前,文件和/或目录已经被 git 跟踪:这意味着,如果您有一个文件
f
在分支b1
中未跟踪,但您签出分支b2
其中该文件 < em>被跟踪,git会无情地覆盖f
。正如上一个问题中提到的,让 git 在“危害造成”后完全忽略此类文件的解决方案包括发出 git rm -r --cached ,然后将它们添加到 .gitignore 中。但这需要逐个分支地完成,这意味着在此期间您仍然会遇到问题。
鉴于您的情况,您有两种选择:
.metadata
放入.gitignore
中——然后先提交,甚至在提交其余部分之前;至于其他IDE要忽略的其他文件,我只能告诉IDEA:
.idea
和*.iml
。不知道其他人...The problem is that the file and/or directory was already tracked by git before you added it to
.gitignore
:This means, among others, that if you have a file
f
which is untracked in branchb1
but you checkout branchb2
in which this file is tracked, git will remorselessly overwritef
.As mentioned in the previous question, the solution to make git completely ignore such files after "the harm is done" consists of issuing
git rm -r --cached
and only then adding them to .gitignore. But this needs to be done branch by branch, which means you will still have the problem in the meantime.Given your situation, you have two choices:
.metadata
immediately into.gitignore
-- and commit that first, before even committing the rest;git filter-branch
.As to other files to ignore with other IDEs, I can only tell for IDEA:
.idea
and*.iml
. No idea for others...