将主人合并到功能分支 [英] Git merge master into feature branch

查看:98
本文介绍了将主人合并到功能分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我们在git中存在以下情况:
$ b

Lets say we have the following situation in git:


  1. 创建的存储库:

  1. A created repository:

mkdir GitTest2
cd GitTest2
git init


$ b

  • Some modifications in the master take place and get committed.

    echo "On Master" > file
    git commit -a -m "Initial commit"
    


  • Feature1分支master和一些工作已经完成:

  • Feature1 branched off master and some work is done:

    git branch feature1
    git checkout feature1
    echo "Feature1" > featureFile
    git commit -a -m "Commit for feature1"
    


  • 在主代码中发现一个错误,并建立一个修复分支

  • Meanwhile, a bug is discovered in the master-code and a hotfix-branch is established

    git checkout master
    git branch hotfix1
    git checkout hotfix1
    


  • 该bug在修补程序分支中得到解决, (或许在拉取请求/代码审查之后):

  • The bug is fixed in the hotfix branch and merged back into the master (perhaps after a pull request/code review):

    echo "Bugfix" > bugfixFile
    git commit -a -m "Bugfix Commit"
    git checkout master
    git merge --no-ff hotfix1
    


  • 继续开发feature1:

  • Development on feature1 continues:

    git checkout feature1
    


  • 现在我的问题是:在我的功能分支修补程序,也许是因为该错误也发生在那里。如何在不将提交复制到我的特性分支的情况下实现这一点?我想阻止在功能分支上获得两个与功能实现无关的新提交。如果我使用合并请求,这对我来说特别重要:所有这些提交也将包含在合并请求中,并且必须进行审查,尽管这已完成(因为修补程序已在主服务器中)。

    我不能做一个 git merge master - 仅用于:致命的:不可能快进,堕胎,但我不确定这是否对我有帮助。

    I can not do a git merge master --ff-only: "fatal: Not possible to fast-forward, aborting.", but I am not sure if this helped me.

    推荐答案

    您应该可以重新绑定master上的分支:

    You should be able to rebase your branch on master:

    git checkout feature1
    git rebase master
    

    管理所有出现的冲突。当你到达提交错误修正(已经在master)时,git会说没有改变,可能它们已经被应用了。然后你用 $ b

    Manage all conflicts that arise. When you get to the commits with the bugfixes (already in master), git will say that there were no changes and that maybe they were already applied. You then continue the rebase (while skipping the commits already in master) with

    git rebase --skip
    

    如果您在功能分支上执行 git log ,则会看看错误修复提交只出现一次,并在主部分。

    If you perform a git log on your feature branch, you'll see the bugfix commit appear only once, and in the master portion.

    有关更详细的讨论,请查看上的Git book文档, git rebase https://git-scm.com/docs/git -rebase ),它涵盖了这个确切的用例。

    For a more detailed discussion, take a look at the Git book docs on git rebase (https://git-scm.com/docs/git-rebase) which cover this exact use case.

    这篇关于将主人合并到功能分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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