git 如何将我的“修复分支”从 Android Studio 合并回“主分支”?

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

How can i merge my "Fix branch" back to "Master branch" from Android Studio?

gitandroid-studio

提问by mike_x_

I have created an application in Android Studio and i have integrated it with Git. So far i commit & push my changes to the master branch.

我在 Android Studio 中创建了一个应用程序,并将它与 Git 集成。到目前为止,我提交并将我的更改推送到主分支。

Now i have created a new branch (from master) named "Fix1" and i have committed and pushed my latest changes to this branch. Which are the next steps in order to merge Fix1 back to Master? Can i do it from Android studio?

现在我已经创建了一个名为“Fix1”的新分支(来自 master),并且我已经提交并将我的最新更改推送到这个分支。将 Fix1 合并回 Master 的下一步是什么?我可以从 Android 工作室做吗?

This is what i see as options at the bottom right git menu: Git options in Android Studio

这就是我在右下角 git 菜单中看到的选项: Android Studio 中的 Git 选项

回答by Burhanuddin Rashid

Yes you can.

是的你可以。

  1. First you need to push your code in in your fix1 branch which you already did
  2. Than change your branch to master
  3. Now from top VCS control go to git->pull and select your fix1 branch and than click on pull button
  1. 首先,您需要将代码推送到您已经完成的 fix1 分支中
  2. 比将您的分支更改为 master
  3. 现在从顶部 VCS 控制转到 git->pull 并选择您的 fix1 分支,然后单击 pull 按钮

Now it will merge your fix1 code to master branch

现在它会将您的 fix1 代码合并到 master 分支

回答by Gal Rom

In your case simply move back to master branch go back to branches list - press fix1 branch and press "merge into current" - this will merge fix1 into master.

在您的情况下,只需返回主分支返回分支列表 - 按 fix1 分支并按“合并到当前” - 这会将 fix1 合并到 master 中。

A more general explanation:

更一般的解释:

First of all, make sure you have committed your changes before the merge.

首先,请确保在合并之前已提交更改。

Let's say you have a branch called A and branch called B and you want to merge B into A, so this is what you need to do:

假设您有一个名为 A 的分支和名为 B 的分支,并且您想将 B 合并到 A 中,因此您需要执行以下操作:

  1. Make sure you are on branch A, you can see it displayed by pressing right click on your project --> Git -- > Repository --> branches. The current branch name will appear at the bottom of the branches list(Or at the top of the list marked with yellow from the latest Android studio version )

  2. from this branches list pick the branch you want to merge into the current branch and pick "Merge" in this case pick branch B and press merge

  3. If no conflicts are there - you are done. If there are conflicts then you need to resolve them - android has a nice merging tool - however, you can do it easily yourself - the conflicted files will be colored in red - you will see the conflicts areas with both branches - remove the undesired code - after resolving all the conflicts you need to press CTRL+A to add them to the git - and then commit your branch again --> Done.

  1. 确保您在分支 A 上,您可以通过右键单击您的项目 --> Git --> 存储库 --> 分支来看到它显示出来。当前分支名称将出现在分支列表的底部(或在最新的Android studio 版本中以黄色标记的列表顶部)

  2. 从此分支列表中选择要合并到当前分支中的分支并在这种情况下选择“合并”选择分支 B 并按合并

  3. 如果没有冲突 - 你就完成了。如果存在冲突,那么您需要解决它们 - android 有一个不错的合并工具 - 但是,您可以自己轻松完成 - 冲突的文件将显示为红色 - 您将看到两个分支的冲突区域 - 删除不需要的代码- 解决所有冲突后,您需要按 CTRL+A 将它们添加到 git - 然后再次提交您的分支 --> 完成。

回答by Anupam Haldkar

Follow these steps

按着这些次序

Step 1 - Commit and push your code with repository "fix1"

第 1 步 - 使用存储库“fix1”提交并推送您的代码

Step 2 - Change your branch from "fix1" to master by checking out .

第 2 步 - 通过签出 将您的分支从“fix1”更改为 master。

Step 3 - Now pull the request and choose "fix1" to pull request into master repositories.

第 3 步 - 现在拉取请求并选择“fix1”将请求拉入主存储库。