如何在“工作区”安全地使用 git与分支和.metadata 的级别?

发布于 2024-12-26 10:35:28 字数 283 浏览 4 评论 0原文

我在工作区级别有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本王不退位尔等都是臣 2025-01-02 10:35:28

问题是,在将文件和/或目录添加到 .gitignore 之前,文件和/或目录已经被 git 跟踪:

  • 对于文件,无论如何,它都会继续被跟踪;
  • 对于目录,还将跟踪您将其添加到 .gitignore 时该目录中存在的文件。

这意味着,如果您有一个文件 f 在分支 b1 中未跟踪,但您签出分支 b2 其中该文件 < em>被跟踪,git会无情地覆盖f

正如上一个问题中提到的,让 git 在“危害造成”后完全忽略此类文件的解决方案包括发出 git rm -r --cached ,然后将它们添加到 .gitignore 中。但这需要逐个分支地完成,这意味着在此期间您仍然会遇到问题。

鉴于您的情况,您有两种选择:

  • 如果您有能力“从头开始”重新启动,请立即将 .metadata 放入 .gitignore 中——然后先提交,甚至在提交其余部分之前;
  • 如果你负担不起,你别无选择,只能选择 git filter-branch。

至于其他IDE要忽略的其他文件,我只能告诉IDEA:.idea*.iml。不知道其他人...

The problem is that the file and/or directory was already tracked by git before you added it to .gitignore:

  • for a file, it will continue to be tracked, no matter what;
  • for a directory, files present in this directory at the time you added it to .gitignore will also be tracked.

This means, among others, that if you have a file f which is untracked in branch b1 but you checkout branch b2 in which this file is tracked, git will remorselessly overwrite f.

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:

  • if you can afford to restart "from scratch", do so and put .metadata immediately into .gitignore -- and commit that first, before even committing the rest;
  • if you cannot afford that, you have no choice but a 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文