简体   繁体   English

在Git中将开发分支与本地特征分支合并

[英]Merging develop branch with local feature branch in Git

I have three branches on my local master develop *feature 我在我的本地主管上有三个分支,开发功能

I want to merge changes of develop branch on to my local feature branch Will git merge develop will work or i have to run some other command 我想将develop分支的更改合并到我的本地功能分支上,将git mergedevelop将工作还是我必须运行其他命令

As mentioned by @Tim, make sure you are on any of the two branches, either develop or feature (from the astreks, you probably are on feature branch), using checkout command: git checkout feature or git checkout develop . 正如@Tim所提到的,请使用checkout命令确保您处于开发或功能这两个分支中的任何一个(从astreks中,您可能位于功能分支): git checkout featuregit checkout develop Now, that you are on one of the branches, you can ask git to merge them using merge command. 现在,您在分支之一上,可以使用merge命令让git合并它们。 The merge command will try to do automatic merge between the two branches. merge命令将尝试在两个分支之间进行自动合并。 If it succeeds cleanly, it will create a commit of the resulted merge (the commit will be on the branch you ran the merge command). 如果完全成功,它将创建一个合并结果的提交(该提交将在您运行merge命令的分支上)。 If it fails, it will stop merge, and tell you the files that have conflict (you can also see the list of unmerged files using git status ). 如果失败,它将停止合并,并告诉您有冲突的文件(您也可以使用git status查看未合并文件的列表)。

You can resolve the conflicts either using git mergetool or manually. 您可以使用git mergetool或手动解决冲突。 The former - mergetool - is provides a GUI interface to resolve conflicts which is a nice thing. 前者-mergetool-提供了一个GUI界面来解决冲突,这很不错。 Run git mergetool --tool-help to see a list of available programs. 运行git mergetool --tool-help以查看可用程序列表。 I recommend using p4merge. 我建议使用p4merge。 If you don't have it available, you will need to configure git to use it. 如果您没有它,则需要配置git才能使用它。 I'll add a link to tutorial at the end of my post showing how to do so. 我将在文章末尾添加指向教程的链接,以显示操作方法。 If you are going with the latter - resolving conflicts manually -, then you need to know a couple things: 如果要使用后者(手动解决冲突),那么您需要了解以下几点:

  1. Git marks conflicts in files with a marker like this: Git使用如下标记来标记文件中的冲突:

    <<<<<<< HEAD:index.html <<<<<<< HEAD:index.html

    contact : foo@kozbara.com 联系人:foo@kozbara.com

    please contact us at foo@kozbara.com 请通过foo@kozbara.com与我们联系。

    >>>>>>> anotherbranch:index.html >>>>>>> anotherbranch:index.html

The part before ===== is from the HEAD (the branch you ran the merge from) -- and I have no idea why it's in bold, the part after is from anotherbranch . =====之前的部分来自HEAD(运行合并的分支)-我不知道为什么它以粗体显示,之后的部分来自anotherbranch You should replace the two parts with the desired string and remove the markers (the <<<<, ==== and >>>). 您应该用所需的字符串替换这两个部分,并删除标记(<<<<,====和>>>)。

After that, you use git add <file> to mark the file as resolved. 之后,您可以使用git add <file>将文件标记为已解析。 Then commit after finishing resolving all conflicts. 解决完所有冲突后再提交。

You might need to read this post from git tutorial on merging to have a better understanding. 您可能需要阅读这篇文章从git的教程合并有一个更好的了解。

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

相关问题 合并到开发分支会导致功能分支被删除 - Merging into develop branch causes feature branch to be deleted 问题将Git Feature分支合并到“Beta”分支(在它已经合并到“Develop”分支之后) - Issue merging Git Feature branch into “Beta” branch (after it has already been merged to “Develop” branch) 推送功能分支以使用git开发分支 - Push a feature branch to develop branch using git Git 功能分支以开发分支为父级 - Git feature branch to have develop branch as parent Git 将更新的开发分支合并到本地分支 - Git merge updated develop branch into local branch 没有开发分支的特征分支模型的Git分支策略 - Git branch strategy for feature branch model without a develop branch Git 将开发分支上的功能合并到另一个已经存在的开发分支 - Git merge feature on develop branch to another already existing develop branch Sourcetree git 流程完成功能开发分支但开发分支被保护 - Sourcetree git flow finish feature to develop branch but develop branch is protected git将本地分支与远程分支合并 - git merging local branch with remote branch 如果我忘记推送提交并从本地开发分支创建功能分支,如何解决 GIT 冲突? - How to resolve GIT conflict if I forgot to push the commits and created a feature branch from my local develop branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM