将 Git 存储库保存在 Eclipse 工作区内部还是外部更好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10531272/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:40:02  来源:igfitidea点击:

Is it better to keep Git repository inside or outside of Eclipse workspace?

eclipsegitegit

提问by JamesG

I am a typical Eclipse/Subversion user beginning the migration to Git. I've researched the basic concepts of git and have decided to stick to a one project per repository approach initially to keep things simple. I am still having trouble, though, deciding where to place the repository for each project.

我是一个典型的 Eclipse/Subversion 用户,开始迁移到 Git。我研究了 git 的基本概念,并决定最初坚持每个存储库一个项目的方法以保持简单。但是,我仍然在决定将每个项目的存储库放置在何处时遇到问题。

I have spent a lot of time reviewing the answers to this question, although I believe the author of that question was assuming that you can only use Eclipse to manage the repository if the repository is located within the Eclipse workspace, which is, of course, not true.

我花了很多时间来查看这个问题的答案,尽管我相信那个问题的作者是假设如果存储库位于 Eclipse 工作区中,您只能使用 Eclipse 来管理存储库,当然,不对。

The thing that struck me most about that question, though, was the fact that all but one answer (including the accepted answer) suggested keeping the repository inside the Eclipse workspace, whereas only one answer pointed out that the EGit User Guiderecommends the exact opposite.

不过,这个问题最让我印象深刻的是,除了一个答案(包括已接受的答案)建议将存储库保留在 Eclipse 工作区中之外,只有一个答案指出EGit 用户指南建议完全相反.

It would appear in practice, however, that there are a number of approaches implemented by Eclipse/EGit, some of which seem to contradict the EGit recommendations.

然而,在实践中,Eclipse/EGit 实现了许多方法,其中一些似乎与 EGit 建议相矛盾。

For example, if you use the New Project Wizard to create a New PHP Project from Git and the repository is remote, Eclipse/EGit will happily create a project folder in the Eclipse workspace and put the repository (.git) in the project folder. This is the end result that I actually want, as it keeps everything encapsulated within the Eclipse workspace.

例如,如果您使用新建项目向导从 Git 创建一个新的 PHP 项目并且存储库是远程的,Eclipse/EGit 会很乐意在 Eclipse 工作区中创建一个项目文件夹,并将存储库 (.git) 放在项目文件夹中。这是我真正想要的最终结果,因为它将所有内容都封装在 Eclipse 工作区中。

However, if you use the New Project Wizard and select a Git repository that is local, Eclipse/EGit doesn't clone the repository like it does for remote repositories. Instead it uses the working copy of that repository as the project location, creates its .project and other meta stuff in that location and also creates a new (seemingly unnecessary) folder within that working copy with the same name as your project (so you end up with, for example, ~/git/blah/blah). If you delete that superfluous folder you end up with a structure that is identical to the first example, the only difference being that the project folder is not a sub-folder of your Eclipse workspace folder, it is somewhere else on your file system (eg. ~/git/blah). The only positive thing this approach seems to have going for it is that it adheres to the recommendations in the EGit User Guide, but from a technical perspective, its hard to see how this is really all that different to the first example.

但是,如果您使用新建项目向导并选择本地 Git 存储库,Eclipse/EGit 不会像克隆远程存储库那样克隆存储库。相反,它使用该存储库的工作副本作为项目位置,在该位置创建其 .project 和其他元数据,并在该工作副本中创建一个新的(看似不必要的)文件夹,其名称与您的项目相同(因此您结束例如, ~/git/blah/blah)。如果删除那个多余的文件夹,您最终会得到与第一个示例相同的结构,唯一的区别是项目文件夹不是 Eclipse 工作区文件夹的子文件夹,它位于文件系统上的其他位置(例如.~/git/blah)。这种方法似乎唯一的好处是它遵守了 EGit 用户指南中的建议,但从技术角度来看,很难看出这与第一个示例有什么不同。

Given these puzzling observations, I'm wondering what sort of experiences people have had using each of these approaches and what the pitfalls might be if one ignores the recommendations in the EGit User Guide.

鉴于这些令人费解的观察结果,我想知道人们使用这些方法中的每一种都有什么样的体验,以及如果忽略 EGit 用户指南中的建议,可能会遇到什么陷阱。

采纳答案by Bananeweizen

The implications of both solutions are listed directly in the user guide that you linked. I can tell you that the part

您链接的用户指南中直接列出了这两种解决方案的含义。我可以告诉你那部分

This can result in performance issues

这可能会导致性能问题

is unfortunately very true. So if you have a git directory with a huge number of files inside your workspace, many git operations will start with a "counting objects..." dialog that blocks your IDE because it scans all files in the workspace. For my current 20000 files this means waiting 10 to 20 seconds for every commit, every switch, ...

不幸的是非常真实。因此,如果您的工作区中有一个包含大量文件的 git 目录,则许多 git 操作将以“计数对象...”对话框开始,该对话框会阻止您的 IDE,因为它会扫描工作区中的所有文件。对于我当前的 20000 个文件,这意味着每次提交、每次切换、……等待 10 到 20 秒。

In spare time activities, where I can fortunately use the other alternative (having the git working directory outside the workspace) everything feels much snappier and it is fun to merge and switch.

在业余活动中,幸运的是我可以使用另一种替代方法(在工作区之外拥有 git 工作目录),一切都感觉更加快捷,合并和切换也很有趣。

So if you go for large projects, consider the git directory outside the workspace as first choice.

因此,如果您进行大型项目,请考虑将工作区外的 git 目录作为首选。

回答by Michel

I am doing the same migration as the original poster and have found another thread where the same doubts are expressed on the Egit recommendation: Should I store git repository in Home or Eclipse Workspace?

我正在做与原始海报相同的迁移,并发现另一个线程对 Egit 建议表达了相同的疑问:我应该将 git 存储库存储在 Home 还是 Eclipse Workspace 中?

@JamesG So this is your layout?

@JamesG 所以这是你的布局?

~/projectA/workspace/.metadata
~/projectA/workspace/subproj1/.project
~/projectA/workspace/subproj2/.project
~/projectA/subproj1/.git
~/projectA/subproj1/file1
~/projectA/subproj2/.git
~/projectA/subproj1/file2