如何将 .git 文件夹保留在克隆的 Eclipse 项目之外
问题
从克隆的 git 存储库导入 Eclipse 项目后,我进行了一些更改并提交 - wtf?我将一个“.git”文件夹添加到项目中,整个 shebang 包含头和引用,最糟糕的是整个对象数据库被添加到项目中,所有文件/文件夹都有这个小问题-mark 图标表示文件尚未添加/尚未被 git 跟踪。这个 .git 文件夹存在于实际的工作目录中(这有什么意义?)。您可以想象在尝试使用“同步”工具/视图时这会带来多大的烦恼(这应该使提交变得更容易,您可以看到所有更改以及更改的文件和差异)。
问题 (tl;dr)
如何从克隆的 git 存储库正确导入 Eclipse 项目?当我提交时,我不希望 .git 文件夹出现在“团队 > 同步”中,请让 .git 文件夹驻留在项目之外的其他位置。
其他信息
我在 Windows 7 上使用 Eclipse Indigo 和 Egit。 我正在使用 Egit 从 http://git.apache.org/ (ofbiz 项目)克隆 git 存储库,准确地说),并在向导中选择从这个新克隆的存储库导入现有项目的选项。
是的,我知道我对 Egit 的期望是多么的少。事实上,如果有任何替代方法(外部 git 工具?Windows 命令行 git?其他?)在 Eclipse 中使用 git 跟踪项目,将实际的 .git 内容保留在项目之外,我很乐意放弃 Egit 。
Issue
After importing an Eclipse project from a cloned git repository, I make some changes and commit - and wtf? I get a ".git" folder added to the project, the whole shebang with the heads and refs and worst of all the whole object database gets added to the project, all files/folders having that little question-mark icon signaling that the files have not been added / are not yet tracked by git. This .git folder exists in the actual Working Directory (how does that even make sense?). You can imagine what an annoyance this causes when trying to use the "Synchronize" tool/view (which is supposed to make life easier for committing, you can see all the changes and changed files and diffs).
Question (tl;dr)
How to correctly import an Eclipse project from a cloned git repository? I don't want a .git folder showing up in "Team > Synchronize" when I commit, let the .git folder reside somewhere else outside of my project.
Additional Info
I'm on Windows 7 using Eclipse Indigo and Egit.
I am using Egit to clone a git repo from http://git.apache.org/ (the ofbiz project, to be exact) and in the wizard I choose the option to import an existing project from this newly cloned repo.
Yes I am aware of how little I may expect from Egit. In fact, if there are any alternative ways (external git tool? command line git for windows? other?) to use a git-tracked project in Eclipse which keeps the actual .git stuff out of the project, i'd gladly abandon Egit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您克隆 git 存储库时,默认行为是在本地克隆的根目录中创建一个 .git 文件夹。您可以通过设置 GIT_DIR 变量来更改默认行为:
Git 文档说:
“GIT_DIR
如果设置了 GIT_DIR 环境变量,那么它会指定要使用的路径,而不是存储库基础的默认 .git。”
根据您使用的终端,您可以使用 setenv 或导出来设置它。
例如在 bash 终端中:
设置变量后,您应该能够克隆,并且 .git 目录应显示在指定目录中。
When you clone a git repository, the default behavior is to create a .git folder inside the root of the local clone. You can change the default behavior by setting the GIT_DIR variable:
Git docs says:
"GIT_DIR
If the GIT_DIR environment variable is set then it specifies a path to use instead of the default .git for the base of the repository."
Depending on which terminal you use, you could set it using setenv or export.
For example in a bash terminal:
After setting the variable, you should be able to clone and the .git directory should show up at the specified directory.
我完全同意 - 我无法想象任何人都会有意提交 .git 文件夹!
并且 git/EGit 知道这是项目的存储库文件夹,因此应该很容易实现适当的异常 - 以便该文件夹不会成为同步的一部分。
我知道以下内容不能解决您的问题,但如果您控制文件在存储库中的布局方式,您可以选择将 Eclipse 项目文件夹不作为存储库的根文件夹,而是一个子文件夹。
这还允许您在存储库中保存不应显示在 Eclipse 中的内容,甚至可以将多个 Eclipse 项目分组在一个存储库中(如果您希望这样做)。
I totally agree - I can't imagine it would ever be anyones intent to commit the .git folder!
And git/EGit knows that this is the repository folder of the project, so it should be easy to implement the appropriate exception - so that this folder does not become part of the synchronization.
I know the following does not solve your problem, but in cases where you control the way files are layed out in the repository, you could choose to have the Eclipse project folder not be the root folder of the repository, but rather a sub-folder.
This also allows you to have stuff in the repository that should not show up in Eclipse, or even have multiple Eclipse projects grouped in one repository (if you should wish to do so).