如何在 Android Studio 中使用 git branch [英] How to use git branch with Android Studio

查看:45
本文介绍了如何在 Android Studio 中使用 git branch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 git 新手.我有一个非常简单的使用 git 的场景.我的第一个版本是用 Android Studio 编写的.现在我想使用一些新功能.到目前为止我做了什么:

I am new to git. I have a very simple scenario for using git. I had my first release written with Android Studio. Now I want to work with some new features. What I did so far:

  1. 在我的 Android Studio 中启用了 VCS
  2. 从 Android Studio 为我的项目创建了一个本地存储库
  3. 将我的本地存储库推送到我的 Bitbucket 远程存储库 ($git push -u origin master)

现在我对下一步感到困惑:创建一个功能分支.我应该在本地存储库中创建一个分支:

Now I am confused for the next step: create a feature branch. Should I create a branch in the local repository:

$ git branch --track feature1 origin/master 

还是应该从 Bitbucket 网络门户创建一个新分支,然后克隆新分支?

or should I create a new branch from the Bitbucket web portal, and clone the new branch?

我也想知道如何用Android Studio切换分支?例如,从功能分支切换到主分支以处理一些修补程序.每次切换分支时,我是否需要使用 Bitbucket 插件从远程存储库中检出项目,或者我可以在 Android Studio 中热切换它?

I also want to know how I can switch branches with Android Studio? For example, switch from feature branch to master branch to work on some hotfix. Do I need to use the Bitbucket plugin to checkout the project very time from the remote repository every time I switch branches or I can hot switch it inside Android Studio?

谢谢!

推荐答案

您应该可以直接从 Android Studio 执行此操作.

You should be able to do this directly from Android studio.

最简单的方法是转到 Android Studio 窗口的右下角,您应该在那里看到文本Git:分支名称",在您的情况下,它应该显示Git:master".单击它,它将显示一个小菜单,其中包含本地和远程可用的不同分支,还应该有一个选项+ New Branch",它将为您创建一个新分支并将您切换到它.

The easiest way is going to the bottom right corner of the Android Studio window where you should see the text "Git: branch name", in your case it should say "Git: master". Click on it and it will show a small menu consisting of the different branches available both locally and remotely, also there should be an option "+ New Branch" which will create a new branch for you and switch you to it.

然后您应该能够更改一些代码、提交并将其推送到远程.合并和检出分支也可以从同一个菜单中完成.同样的事情也可以从菜单栏选项VCS"中完成

You should then be able to change some code, commit it and push it to remote. Merging and checking out branches can also be done from that same menu. The same thing can also be done from the menubar option "VCS"

这篇关于如何在 Android Studio 中使用 git branch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆