简体   繁体   English

如何在git中合并和推送本地分支

[英]How to merge and push a local branch in git

Hi I am in difficulty with this scenarios: I have two local branch: develop and branch1 . 嗨,我在这种情况下遇到了麻烦:我有两个本地分支: developbranch1 On remote I have develop branch only. 在远程,我只有开发分支。

The steps that i followed: 我遵循的步骤:

  • I have pulled remote develop from my local develop. 我从本地开发中撤走了远程开发。
  • I have created new branch branch1 and add some code inside it. 我创建了新的分支branch1并在其中添加了一些代码。

I need to create, and push all the modification of branch1 on remote. 我需要创建并在远程上推送分支1的所有修改。 After doing it I am costrained to go to github and make a pull request from my "branch1" remote branch to the develop remote branch. 完成此操作后,我非常费心去github并从我的“ branch1”远程分支向开发远程分支发出拉取请求。

Which are the steps that I need to do in case of conflicts? 如果发生冲突,我需要执行哪些步骤? I try to read a lot but the major part are merging in local and push on develop ( or master ) but my scenario is different cause i need to push on remote branch1 and from there to ask to review the code from a person and make a pull request. 我尝试阅读很多书,但是主要部分是在本地合并并进行开发(或掌握),但是我的情况是不同的,因为我需要继续进行远程branch1并从那里请求查看人的代码并制作一个拉取请求。 I need to avoid conflicts. 我需要避免冲突。

If I understand your question: 如果我了解您的问题:

  • You are following a standard pull request workflow that merges feature branches ("branch1") into a long-lived "develop" branch. 您正在遵循标准的拉取请求工作流程,该工作流程将要素分支(“ branch1”)合并为一个长期存在的“ develop”分支。
  • Sometimes, as a result of the peer review process, you end up with merge conflicts. 有时,由于同行评审过程的结果,您最终会遇到合并冲突。 You want to avoid this. 您要避免这种情况。

Solution: 解:

Avoiding merge conflicts: 避免合并冲突:

There is no way to "avoid" merge conflicts in a workflow such as this one (or in any workflow, really). 在这种工作流中(或实际上在任何工作流中),都无法“避免”合并冲突。 The best you can do is to remind the peer reviewer that time-consuming merge conflicts are likely to occur unless they are reviewed and merged quickly. 您能做的最好的事情就是提醒同行审阅者,除非进行快速的审阅和合并,否则很可能会发生耗时的合并冲突。

Resolving merge conflicts: 解决合并冲突:

Most of the time, resolving the merge conflicts in this workflow is easy: 在大多数情况下,解决此工作流程中的合并冲突很容易:

  • In your local copy, checkout develop: 在您的本地副本中,结帐功能如下:
git pull origin develop
  • Rebase "branch1" against develop: 对“ branch1”重新设置开发基础:
git checkout branch1
git rebase develop
  • Interactively resolve the merge conflicts. 交互式解决合并冲突。

You really do need to know how to resolve merge conflicts, eg ref . 您确实确实需要知道如何解决合并冲突,例如ref

  • Push branch1: 推送分支1:
git push origin branch1 --force

(Force is required because the rebase operation rewrites the history.) (因为重新设置操作会重写历史记录,所以必须使用强制。)

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

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