简体   繁体   English

在 Eclipse 中的 git 分支之间切换

[英]Switching between git branches in Eclipse

I have cloned two branches inside same eclipse workspace.我在同一个 eclipse 工作区中克隆了两个分支。 Hence it has 2 cloned repositories.因此它有 2 个克隆的存储库。 Whenever I launch eclipse it opens one of the repositories.每当我启动 eclipse 时,它​​都会打开其中一个存储库。 How to switch eclipse to point to the other repository?如何切换 eclipse 以指向另一个存储库?

To switch branches from within Eclipse从 Eclipse 中切换分支

  1. Right click project in the explorer window (by default it's on the left side)在资源管理器窗口中右键单击项目(默认情况下它在左侧)
  2. Go to Team进入团队
  3. Go to Switch To转到切换到
  4. Select a branch to switch to选择要切换的分支

Eclipse will now update the project and files to match the branch Eclipse 现在将更新项目和文件以匹配分支

If you have 2 repositories (one branch in each repository), this means that you unnecessary created them.如果您有 2 个存储库(每个存储库中有一个分支),这意味着您没有必要创建它们。 You can have both branches in only one repository.您只能在一个存储库中拥有两个分支。

In Git Repositories tab, after clone a repository, you should click it with right button -> "Fetch from origin" -> Configure -> Add -> type wanted branch -> Save and Fetch.在 Git Repositories 选项卡中,克隆一个存储库后,您应该右键单击它 -> "Fetch from origin" -> Configure -> Add -> 输入想要的分支 -> Save and Fetch。

If you'd like use one branch per repository, so to show others repositories, in Git Repositories tab you should click "Add an existing local Git Repository to this view" icon and select the wanted repository.如果您希望每个存储库使用一个分支,以便显示其他存储库,请在 Git 存储库选项卡中单击“将现有本地 Git 存储库添加到此视图”图标并选择所需的存储库。

Try this on the terminal在终端上试试这个

Git checkout banchName

And if you clone 2 branches you will have one repository with 2 branches.如果您克隆 2 个分支,您将拥有一个包含 2 个分支的存储库。

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

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