多个 Eclipse 项目中的多个 Git 分支

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

Multiple Git Branches in Multiple Eclipse Projects

eclipsegitsvnbranch

提问by Greg Kennedy

We're in the process of converting from Subversion to Git and one thing that I'm struggling with in Git is the method of switching branches.

我们正在从 Subversion 转换到 Git,我在 Git 中遇到的一件事是切换分支的方法。

My understanding is that at both at the command line and using EGit in Eclipse that switching to a different branch replaces the contents of the Eclipse workspace folder with that of the desired branch. This implies only one branch can be open at any one time.

我的理解是,在命令行和在 Eclipse 中使用 EGit 时,切换到不同的分支会将 Eclipse 工作区文件夹的内容替换为所需分支的内容。这意味着在任何时候只能开设一家分行。

In SVN I could arrange my Eclipse workspace similar to:

在 SVN 中,我可以将我的 Eclipse 工作区安排为类似于:

Workspace/
   Project1Branch/
   Project2Branch/
   Project3/
   Project4Branch/

Is it possible to have multiple Git branches open at the same time in the same Eclipse/Egit workspace ( or any other environment for that matter )?

是否可以在同一个 Eclipse/Egit 工作区(或任何其他环境)中同时打开多个 Git 分支?

回答by Greg Kennedy

After much testing and a sanity check from @MarkLeightonFisher it seems it is notpossible to have multiple Git branches open in the same Eclipse workspace at the same time.

许多测试和从@MarkLeightonFisher完整性检查后,似乎就没有可能有多个的Git分支在同一Eclipse工作空间打开在同一时间

回答by A. Assaad

Indeed you can't import multiple branches from the same git repository into the workspace, because it only has one working directory which can contain only one checked branch. Here's a very reasonable workaround that accommodates this feature of git (I do it and it works well): Clone the git repository in a second directory (or 3rd or 4th even), then change the name of the project manually by editing .project and changing the <name> element. You can now import this project alongside the original, and work on multiple branches at the same time in the same workspace. Caveat: Get very friendly with the "Close Project" menu item so you can avoid cross-editing (it gets confusing sometimes when you have many source windows open with the same file name...)

事实上,你不能从同一个 git 存储库中将多个分支导入到工作区中,因为它只有一个工作目录,其中只能包含一个选中的分支。这是一个非常合理的解决方法,它适应了 git 的这个特性(我这样做了并且效果很好):将 git 存储库克隆到第二个目录(甚至第 3 个或第 4 个目录)中,然后通过编辑 .project 和更改 <name> 元素。您现在可以将此项目与原始项目一起导入,并在同一工作区中同时处理多个分支。警告:对“关闭项目”菜单项非常友好,这样您就可以避免交叉编辑(当您打开许多具有相同文件名的源窗口时,有时会令人困惑......)

回答by Pellekrino

Actually i managed to do it :

其实我设法做到了:

You can have multiple workspaces for one git repository : this is called "worktree". (limitation is that for obvious reason, you can't checkout same local branch in 2 different work trees. Well, you shouldn't, but some commands may lead you to be in such situation.)

一个 git 存储库可以有多个工作区:这称为“工作树”。(限制是由于显而易见的原因,您不能在 2 个不同的工作树中检出同一个本地分支。好吧,您不应该这样做,但是某些命令可能会导致您处于这种情况。)

https://git-scm.com/docs/git-worktree

https://git-scm.com/docs/git-worktree

Then you can create one eclipse-workspace for each of your work-tree.

然后,您可以为每个工作树创建一个 eclipse 工作区。