你如何将选择性文件与git-merge合并? [英] How do you merge selective files with git-merge?

查看:1119
本文介绍了你如何将选择性文件与git-merge合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个新项目上使用git,这个项目有两个平行但目前是实验开发分支: c $ c> master :导入现有的代码库,加上我通常可以确定的几个mod

  • exp1 :实验分支#1
  • exp2 :实验分支#2



  • exp1 exp2 表示两种非常不同的架构方法。直到我得到更进一步,我无法知道哪一个(如果有)将工作。当我在一个分支中取得进展时,我有时会对其他分支有用的编辑进行编辑,并希望仅合并这些分支。

    什么是最佳方式将选择性文件从一个开发分支合并到另一个开发分支,同时留下一切?



    方法我考虑过:


    1. git merge --no-commit 然后手动取消大量编辑, t

    2. 手动将常用文件复制到临时目录中,然后加上 git checkout 移动到另一个分支,然后再从临时目录复制到工作树中。


    3. 上述变体。现在放弃 exp 分支并使用两个额外的本地存储库进行实验。这使得手动复制文件变得更直接。

    4. b
      $ b

      这三种方法看起来都很乏味且容易出错。我希望有更好的方法;类似于过滤器路径参数,这将使 git-merge 更具选择性。

      解决方案

      您使用 cherry-pick 命令获取单个提交来自一个分支。

      如果您想要的更改不在单个提交中,请使用此处显示的方法将提交拆分为单个提交。粗略地说,您使用 git rebase -i 来获取原始提交进行编辑,然后使用 git reset HEAD ^ 选择恢复更改,然后 git commit 将该位作为新的提交提交给历史记录。

      红帽杂志里有另一个不错的方法他们使用 git add --patch 或可能 git add --interactive ,它允许您添加大块的部分,如果你想分割不同的变化到一个单独的文件(在该页面搜索拆分)。



      分割变化后,你现在可以选择樱桃你想要的。


      I'm using git on a new project that has two parallel -- but currently experimental -- development branches:

      • master: import of existing codebase plus a few mods that I'm generally sure of
      • exp1: experimental branch #1
      • exp2: experimental branch #2

      exp1 and exp2 represent two very different architectural approaches. 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.

      What is the best way to merge selective files from one development branch to another while leaving behind everything else?

      Approaches I've considered:

      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.

      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.

      3. A variation on the above. Abandon the exp branches for now and use two additional local repositories for experimentation. This makes the manual copying of files much more straightforward.

      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.

      解决方案

      You use the cherry-pick command to get individual commits from one branch.

      If the change(s) you want are not in individual commits, then use the method shown here to split the commit into individual commits. Roughly speaking, you use git rebase -i to get the original commit to edit, then git reset HEAD^ to selectively revert changes, then git commit to commit that bit as a new commit in the history.

      There is another nice method here in Red Hat Magazine, where they use git add --patch or possibly git add --interactive which allows you to add just parts of a hunk, if you want to split different changes to an individual file (search in that page for "split").

      Having split the changes, you can now cherry-pick just the ones you want.

      这篇关于你如何将选择性文件与git-merge合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆