简体   繁体   English

Git - 将发布分支合并到主分支

[英]Git - Merging release branch into master

I have a master branch and release branches in my git repository which is hosted on bitbucket.我的 git 存储库中有一个主分支和发布分支,该存储库托管在 bitbucket 上。 I got a merge conflict when I merged release branch r1 into master.当我将发布分支 r1 合并到 master 时,我遇到了合并冲突。 The merge conflict was only due to a read me text file.合并冲突仅是由于自述文本文件所致。 I want to keep the readme file of r1 and reject the one in master.我想保留 r1 的自述文件并拒绝 master 中的文件。

I fixed the conflict and got an error when I pushed the merged code - "branch can only be modified through pull requests".当我推送合并的代码时,我修复了冲突并出现错误 - “分支只能通过拉取请求修改”。 I know this happens because we are not allowed to push directly into master.我知道发生这种情况是因为我们不允许直接推入 master。 How do I merge r1 into master in this case?在这种情况下,如何将 r1 合并到 master 中?

You should to update the r1 branch with master .您应该使用master更新r1分支。 And then merge r1 into master using "Pull Request".然后使用“拉取请求”将r1合并到master中。

There are two ways to update r1 :更新r1有两种方法:

  1. Merge master into r1合并masterr1

     git checkout r1 // checkout to branch r1 git fetch origin master // fetch the latest version of master from origin git merge origin/master // merge the latest version of master into r1 branch git push // push new version of r1 to remote repository
  2. Rebase r1 on mastermaster服务器上重新设置r1

     git checkout r1 // checkout to branch r1 git fetch origin master // fetch the latest version of master from origin git rebase origin/master // rebase r1 branch on the latest version of master git push --force // push new version of r1 to remote repository

    why --force ?为什么--force see here https://stackoverflow.com/a/8940299/5599567 )见这里https://stackoverflow.com/a/8940299/5599567

You should resolve the conflicts in your release branch.您应该解决发布分支中的冲突。 There are two solutions to do so.有两种解决方案可以做到这一点。 The first one is to rebase your release branch on top of master, but you will have to force push, so you need to be sure that you'll not override someone else commit:第一个是在 master 之上 rebase 你的发布分支,但是你必须强制推送,所以你需要确保你不会覆盖其他人的提交:

git checkout r1
git fetch origin master
git rebase origin/master

Resolve your conflicts, then解决你的冲突,然后

git push -f

Otherwise you merge master in release, you resolve your conflicts and then you push.否则,您将 master 合并到 release 中,解决您的冲突,然后推送。

Once the conflicts are resolved, you can create a pull request to merge release in master.解决冲突后,您可以创建拉取请求以合并 master 中的发布。

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

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