git 如何移动 Egit 存储库和工作目录

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

How to move Egit repository and working directory

eclipsegitegit

提问by jfritz42

I am new to Egit and created a new repository for a GWT project I'm working on. Unfortunately, I let it create the repository under my Dropbox folder, and now I'm regretting it because I'm syncing megabytes of temp files (e.g. *.class) over the internet. The "create repository" wizard also moved the project's files from the Eclipse workspace to a working directory under Dropbox (along with the .git folder).

我是 Egit 的新手,并为我正在处理的 GWT 项目创建了一个新存储库。不幸的是,我让它在我的 Dropbox 文件夹下创建存储库,现在我很后悔,因为我正在通过互联网同步数兆字节的临时文件(例如 *.class)。“创建存储库”向导还将项目文件从 Eclipse 工作区移动到 Dropbox 下的工作目录(以及 .git 文件夹)。

What is an easy way for me to move this Egit repository and working directory to somewhere else, other than the Dropbox folder?

有什么简单的方法可以让我将此 Egit 存储库和工作目录移动到 Dropbox 文件夹以外的其他地方?

(btw, since I'm using Egit, the solution needs to work such that Eclipse is happy and I can keep building/using my project).

(顺便说一句,因为我使用的是 Egit,所以该解决方案需要工作,以便 Eclipse 满意并且我可以继续构建/使用我的项目)。

回答by jfritz42

I managed to do it myself, here's how:

我自己设法做到了,方法如下:

  • In Eclipse, right-click MyApp project, Refactor->Move. Move the Eclipse project to a new spot on disk. Note that I kept the .../GitRepositories/MyApp/MyAppdir structure, it's just that I moved the location of GitRepositories to a new place. Also note that this left the old dir with nothing but the .git folder inside it (i.e. Eclipse moved the working files/dirs but not the repo).
  • Close Eclipse
  • Move the .git directory from the old directory to the new. Be sure to keep it in the right relative place! I accidentally moved .git from .../GitRepositories/MyAppto .../GitRepositories/MyApp/MyApp. This screwed things up and I had to back track...
  • Start Eclipse
  • 在 Eclipse 中,右键单击 MyApp 项目,Refactor->Move. 将 Eclipse 项目移动到磁盘上的新位置。请注意,我保留了.../GitRepositories/MyApp/MyAppdir 结构,只是将 GitRepositories 的位置移动到了新位置。另请注意,这使旧目录中只有 .git 文件夹(即 Eclipse 移动了工作文件/目录而不是 repo)。
  • 关闭日食
  • 将 .git 目录从旧目录移动到新目录。一定要把它放在正确的相对位置!我意外移动git的,从.../GitRepositories/MyApp.../GitRepositories/MyApp/MyApp。这把事情搞砸了,我不得不回溯......
  • 启动日食

It might already work at this point, but because I moved .git to the wrong place when I first did it, I had to do the following steps:

此时它可能已经工作了,但是因为我第一次将 .git 移到了错误的位置,所以我必须执行以下步骤:

  • Right-click MyApp project, Team->Disconnect
  • Right-click MyApp project, Team->Share Project...
  • The wizard automatically finds the Git report relative to the project dir: ../.git
  • 右键单击 MyApp 项目, Team->Disconnect
  • 右键单击 MyApp 项目, Team->Share Project...
  • 向导会自动查找与项目目录相关的 Git 报告: ../.git

Happy hacking...

快乐的黑客...

回答by jthodges

When working with a local repository, you can just do the following:

使用本地存储库时,您只需执行以下操作:

  1. Close Eclipse
  2. Move the git repository on disk
  3. Reopen Eclipse
  4. Select File->Import... -> Git -> Projects from Git
  5. Select local repository and add the new repository location
  6. Select your project(s) to be added
  7. (Optional) Remove the old project references from your workspace.
  1. 关闭日食
  2. 将 git 存储库移动到磁盘上
  3. 重新打开 Eclipse
  4. 选择 File->Import...->Git->Projects from Git
  5. 选择本地存储库并添加新的存储库位置
  6. 选择要添加的项目
  7. (可选)从您的工作区中删除旧的项目引用。

It may seem like a lot of steps, but it's actually very simple and less invasive than moving the repo and working copy separately.

这看起来似乎有很多步骤,但实际上它比单独移动存储库和工作副本非常简单且侵入性更小。