Git将主合并到功能分支

本文翻译自:Git merge master into feature branch

Let's say we have the following situation in Git: 假设我们在Git中有以下情况:

  1. A created repository: 创建的存储库:

     mkdir GitTest2 cd GitTest2 git init 
  2. Some modifications in the master take place and get committed. 在主服务器中进行一些修改并落实。

     echo "On Master" > file git commit -a -m "Initial commit" 
  3. Feature1 branched off master and some work is done: Feature1从master分支出来,并完成了一些工作:

     git branch feature1 git checkout feature1 echo "Feature1" > featureFile git commit -a -m "Commit for feature1" 
  4. Meanwhile, a bug is discovered in the master-code and a hotfix-branch is established 同时,在主代码中发现一个错误并建立了一个热修复分支。

     git checkout master git branch hotfix1 git checkout hotfix1 
  5. The bug is fixed in the hotfix branch and merged back into the master (perhaps after a pull request/code review): 该错误已在hotfix分支中修复,并重新合并到master中(可能在请求请求/代码审查之后):

     echo "Bugfix" > bugfixFile git commit -a -m "Bugfix Commit" git checkout master git merge --no-ff hotfix1 
  6. Development on feature1 continues: 继续对feature1进行开发:

     git checkout feature1 

Say I need the hotfix in my feature branch, maybe because the bug also occurs there. 假设我在功能分支中需要此修补程序,也许是因为该错误也发生在这里。 How can I achieve this without duplicating the commits into my feature branch? 如何在不将提交复制到功能分支的情况下实现此目标?

I want to prevent to get two new commits on my feature branch which have no relation to the feature implementation. 我想防止在功能分支上获得两个与功能实现无关的新提交。 This especially seems important for me if I use pull requests: All these commits will also be included in the pull request and have to be reviewed although this has already been done (as the hotfix is already in the 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. 我不能做一个git merge master --ff-only :“致命的:不可能快速前进,中止。”但是我不确定这是否对我有帮助。


#1楼

参考:https://stackoom.com/question/1991Y/Git将主合并到功能分支


#2楼

You should be able

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值