简体   繁体   English

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

[英]Multiple Git Branches in Multiple Eclipse Projects

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. 我的理解是,在命令行和Eclipse中使用EGit时,切换到不同的分支会将Eclipse工作区文件夹的内容替换为所需分支的内容。 This implies only one branch can be open at any one time. 这意味着任何时候只能打开一个分支。

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分支?

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

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. 实际上,您无法将多个分支从同一个git存储库导入工作空间,因为它只有一个工作目录,只能包含一个已检查的分支。 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. 这是一个非常合理的解决方法,适应git的这个功能(我做它并且运行良好):在第二个目录(或第三个或第四个偶数)中克隆git存储库,然后通过编辑.project手动更改项目的名称。更改<name>元素。 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...) 警告:使用“关闭项目”菜单项非常友好,这样您就可以避免交叉编辑(当您使用相同的文件名打开许多源窗口时,它会变得混乱...)

Actually i managed to do it : 实际上我设法做到了:

You can have multiple workspaces for one git repository : this is called "worktree". 您可以为一个git存储库提供多个工作区:这称为“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.) (限制是因为显而易见的原因,你不能在两个不同的工作树中检查相同的本地分支。嗯,你不应该,但是一些命令可能会导致你处于这种情况。)

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工作区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM