如何将移动的 git 存储库与其在 Egit 中的原始项目重新连接?

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

How do I reconnect a moved git repository with it's original project in Egit?

eclipsegitrepositoryegit

提问by Jonathan

I have a number of projects within an Eclipse workspace. One project is connected with a git repository. This is the original directory/project structure:

我在 Eclipse 工作区中有许多项目。一个项目与一个 git 存储库相连。这是原始目录/项目结构:

Eclipse_workspace
  Eclipse_workspace/Project1
    Eclipse_workspace/Project1/.git
  Eclipse_workspace/Project2

After reading about the complications that can arise from keeping a git repository within the parent directory of a project in a workspace (here), I decided it would be best to move the repository outside the workspace. Here is the revised structure:

在阅读了将 git 存储库保留在工作区中项目的父目录中可能引起的复杂情况后(此处),我决定最好将存储库移到工作区之外。这是修改后的结构:

Eclipse_workspace
  Eclipse_workspace/Project1
    Eclipse_workspace/Project1
  Eclipse_workspace/Project2
.git
  .git/Project1

Within the "Git Repositories" view I re-added the repository. I thought it would be simple to reconnect the repository to "Project1" by altering a few file path settings. I found that this was not possible from Project1's properties (right click on project -> properties). I noticed that within the "Share Project" wizard you can connect to an "existing repository". So I disconnected the project from the now non-existent repository and I tried to reconnect it using the "Share Project" wizard. But although the repository is shown in the "Git Repositories" view, I was unable to select it. I clicked the "create" button and tried typing in the file path but this gave me an error stating that the directory is "not empty".

在“Git 存储库”视图中,我重新添加了存储库。我认为通过更改一些文件路径设置将存储库重新连接到“Project1”会很简单。我发现从 Project1 的属性中这是不可能的(右键单击项目 -> 属性)。我注意到在“共享项目”向导中,您可以连接到“现有存储库”。因此,我将项目与现在不存在的存储库断开连接,并尝试使用“共享项目”向导重新连接它。但是,尽管存储库显示在“Git 存储库”视图中,但我无法选择它。我单击“创建”按钮并尝试输入文件路径,但这给了我一个错误,指出该目录“非空”。

So I have now become stuck as there seems to be no other options available. How can I reconnect this repository? I'm surprised by how complicated this is, I must be doing something really obviously wrong. I really need to get on with some work and messing around with Egit is taking up all of my time.

所以我现在陷入困境,因为似乎没有其他选择。如何重新连接此存储库?我很惊讶这是多么复杂,我一定是在做一些明显错误的事情。我真的需要继续做一些工作,而与 Egit 混在一起占用了我所有的时间。

回答by pprain

I ran into this same problem and here was my solution:

我遇到了同样的问题,这是我的解决方案:

  1. Copy your repository(including the .git directory and the working directory) to wherever your new location.
  2. Add your new repository in the "Git Repositories" view in eclipse.
  3. Then import your "Projects from Git".
  1. 将您的存储库(包括 .git 目录和工作目录)复制到您的新位置。
  2. 在 Eclipse 的“Git Repositories”视图中添加您的新存储库。
  3. 然后导入您的“来自 Git 的项目”。

The point is: try not to reconnect, just import the projects from your new repository into your eclipse workspace.

重点是:尽量不要重新连接,只需将新存储库中的项目导入到 eclipse 工作区中即可。

Hope this helps.

希望这可以帮助。