Git将主合并到功能分支 - Git merge master into feature branch

06/23 03:31
阅读数 615

问题:

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 :“致命的:不可能快速前进,中止。”但是我不确定这是否对我有帮助。


解决方案:

参考一: https://stackoom.com/question/1991Y/Git将主合并到功能分支
参考二: https://oldbug.net/q/1991Y/Git-merge-master-into-feature-branch
展开阅读全文
打赏
1
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
1
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部