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

问题:

Let's say we have the following situation in Git: 假设咱们在Git中有如下状况: git

  1. A created repository: 建立的存储库: 服务器

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

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

    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 同时,在主代码中发现一个错误并创建了一个热修复分支。 .net

    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中(可能在请求请求/代码审查以后): code

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

    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). 若是我使用拉取请求,这对我来讲尤为重要:全部这些提交也将包含在拉取请求中,尽管已经完成(由于此修补程序已在主服务器中),但必须进行审查。 get

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


解决方案:

参考一: https://stackoom.com/question/1991Y/Git将主合并到功能分支
参考二: https://oldbug.net/q/1991Y/Git-merge-master-into-feature-branch
相关文章
相关标签/搜索