如何有选择地合并或选择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
相关文章
相关标签/搜索