問題:
Let's say we have the following situation in Git: 假設咱們在Git中有如下狀況: git
A created repository: 建立的存儲庫: 服務器
mkdir GitTest2 cd GitTest2 git init
Some modifications in the master take place and get committed. 在主服務器中進行一些修改並落實。 this
echo "On Master" > file git commit -a -m "Initial commit"
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"
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
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
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