如何有選擇地合併或選擇Git中另外一個分支的更改? - How to selectively merge or pick changes from another branch in Git?

問題:

I'm using git on a new project that has two parallel -- but currently experimental -- development branches: 我在一個新項目上使用git,該項目有兩個並行的但目前仍處於試驗階段的開發分支: git

  • master : import of existing codebase plus a few mods that I'm generally sure of master :導入現有的代碼庫以及一些我一般肯定的mod
  • exp1 : experimental branch #1 exp1 :實驗分支1
  • exp2 : experimental branch #2 exp2 :實驗分支2

exp1 and exp2 represent two very different architectural approaches. exp1exp2表明兩種很是不一樣的體系結構方法。 Until I get further along I have no way of knowing which one (if either) will work. 直到我步入正軌,我才知道哪個(若是有的話)會工做。 As I make progress in one branch I sometimes have edits that would be useful in the other branch and would like to merge just those. 當我在一個分支中取得進展時,有時我會進行一些編輯,而這些編輯在另外一分支中將很是有用,而且但願將這些合併。 app

What is the best way to merge selective changes from one development branch to another while leaving behind everything else? 將選擇的更改從一個開發分支合併到另外一個開發分支,同時又保留其餘全部分支的最佳方法是什麼? ide

Approaches I've considered: 我考慮過的方法: spa

  1. git merge --no-commit followed by manual unstaging of a large number of edits that I don't want to make common between the branches. git merge --no-commit而後手動取消暫存我不想在分支之間共享的大量編輯。 .net

  2. Manual copying of common files into a temp directory followed by git checkout to move to the other branch and then more manual copying out of the temp directory into the working tree. 手動將經常使用文件複製到temp目錄中,而後git checkout移至另外一個分支,而後從temp目錄中進行更多手動複製到工做樹中。 code

  3. A variation on the above. 上面的變化。 Abandon the exp branches for now and use two additional local repositories for experimentation. 如今放棄exp分支,並使用另外兩個本地存儲庫進行實驗。 This makes the manual copying of files much more straightforward. 這使得手動複製文件更加簡單。 three

All three of these approaches seem tedious and error-prone. 全部這三種方法彷佛都是乏味且容易出錯。 I'm hoping there is a better approach; 我但願有更好的方法; something akin to a filter path parameter that would make git-merge more selective. 相似於filter path參數,可使git-merge更具選擇性。 開發


解決方案:

參考一: https://stackoom.com/question/1swf/如何有選擇地合併或選擇Git中另外一個分支的更改
參考二: https://oldbug.net/q/1swf/How-to-selectively-merge-or-pick-changes-from-another-branch-in-Git
相關文章
相關標籤/搜索