为什么不建议将 Eclipse 项目文件夹作为 Git 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14107367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is not recommended to have an Eclipse project folder as a Git repository?
提问by David Hofmann
When sharing a project as git and trying to make the Eclipse project folder as the git repository, Eclipse says that it is not recommended to do so and that it should be outside the Eclipse workspace.
将项目共享为 git 并尝试将 Eclipse 项目文件夹设为 git 存储库时,Eclipse 表示不建议这样做,它应该位于 Eclipse 工作区之外。
Why is that?
这是为什么?
采纳答案by cacba
From Eclipse EGit help pages,
It is probably not a good idea to make a project the root folder of your Repository
The reason is that you will never be able to add another project to this Repository, as the .project file will occupy the root folder; you could still add projects as sub-folders, but this kind of project nesting is known to cause lots of problems all over the place. In order to add another project, you would have to move the project to a sub-folder in the Repository and add the second project as another sub-folder before you could commit this change.
将项目作为存储库的根文件夹可能不是一个好主意
原因是您将永远无法向此 Repository 添加另一个项目,因为 .project 文件将占用根文件夹;您仍然可以将项目添加为子文件夹,但众所周知,这种项目嵌套会导致很多问题。为了添加另一个项目,您必须先将该项目移动到存储库中的一个子文件夹并将第二个项目添加为另一个子文件夹,然后才能提交此更改。
Some more information
更多信息
It is a good idea to keep your Repository outside of your Eclipse Workspace
There are several reasons for this:
The new Repository will consider the complete folder structure of the Eclipse workspace as (potential) content. This can result in performance issues, for example when calculating the changes before committing (which will scan the complete .metadata folder, for example); more often than not, the workspace will contain dead folders (e.g. deleted projects) which semantically are not relevant for EGit but can not be excluded easily.
The metadata (.git-) folder will be a child of the Eclipse Workspace. It is unclear whether this might cause unwanted folder traversals by Eclipse.
You can easily destroy your Repository by destroying your Eclipse Workspace
将您的存储库放在 Eclipse 工作区之外是个好主意
有几个原因:
新的 Repository 会将 Eclipse 工作区的完整文件夹结构视为(潜在的)内容。这可能会导致性能问题,例如在提交之前计算更改时(例如,这将扫描完整的 .metadata 文件夹);通常情况下,工作区将包含死文件夹(例如已删除的项目),这些文件夹在语义上与 EGit 无关,但不能轻易排除。
元数据 (.git-) 文件夹将是 Eclipse 工作区的子项。目前尚不清楚这是否会导致 Eclipse 进行不需要的文件夹遍历。
您可以通过销毁 Eclipse 工作区轻松销毁您的存储库
回答by VonC
While I agree about keeping the repository outside the Eclipse workspace, and I would still make a git repo within an Eclipse project root directory (like in this answer).
虽然我同意将存储库保留在 Eclipse 工作区之外,但我仍然会在 Eclipse 项目根目录中创建一个 git repo(就像在这个答案中一样)。
Unless your program is composed of lots of little inter-dependent projects, I would limit one git repo to one Eclipse project.
A git repo is about recording the contentof a tree structure, and if that tree represents oneproject, it is easier to manage, tag, branch, merge (as a coherent set of files).
If it represents multiple project, you are not sure anymore about what a tag like "1.0" represents for each of the projects in that Git repo.
除非您的程序由许多相互依赖的小项目组成,否则我会将一个 git repo 限制为一个 Eclipse 项目。
git repo 是关于记录树结构的内容,如果该树代表一个项目,则更容易管理、标记、分支、合并(作为一组连贯的文件)。
如果它代表多个项目,则您不再确定像“1.0”这样的标签代表该 Git 存储库中的每个项目。
Plus, I like to add the .project
, .classpath
and .settings
to the Git repo (as "Does git exclude eclipse project files from a new repo by default?")
另外,我喜欢将.project
,.classpath
和添加.settings
到 Git 存储库(如“默认情况下 git 是否从新存储库中排除 eclipse 项目文件?”)