如何git-cherry-pick仅更改某些文件?
|
如果我想合并到Git分支中,而只对某些提交中的某些文件所做的更改(包括对多个文件的更改)进行更改,那么如何实现呢?
假设名为
stuff
的Git提交对文件A
,B
,C
和D
进行了更改,但是我只想将stuff
\的更改合并到文件A
和B
。这听起来像是a8ѭ的工作,但cherry-pick
只知道如何合并整个提交,而不是文件的子集。
没有找到相关结果
已邀请:
12 个回复
窝头菊
(
)来做,让您在提交之前检查(和修改)结果:
如果绝大多数修改是您不想要的,那么您可以将所有内容重置为零,然后添加所需的内容,而不用检查单个路径(中间步骤):
蓄荣糖些
它实际上并不会“ѭ15”个文件或为您执行一次提交,因此您可能需要跟进
或者,如果要跳过添加,则可以将
参数用于
您还可以对整个目录执行相同的操作
素汞读
标志与其他分支的git checkout一起使用,与我遇到的大多数其他方法相比,我发现它更容易且更精细。 原则上:
例:
然后,您会看到一个对话框,询问您要在\“ blobs \”中进行哪些更改,这几乎可以解决连续代码更改的每个块,然后您可以为每个代码块发出
(是)
(否)等信号。
或
选项可用于git中的各种命令,包括
,可让您从当前工作中选择要隐藏的内容 当我做了很多工作时,有时我会使用这种技术,想将其分离出来并使用
提交更多基于主题的提交,并为每次提交选择想要的内容:)
凡夕
外镶受继
例如:
来源和完整说明http://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/ 更新: 使用这种方法,git将不会合并文件,它将覆盖目标分支上所做的任何其他更改。您将需要手动合并更改: $ git diff HEAD文件名
诧不达
,并且在其他任何分支上都有提交。您只需要从该特定提交中选择一个文件。 该方法: 步骤1:在所需分支上签出。
步骤2:确保已复制所需的提交哈希。
步骤3:现在,您可以在所需分支上更改所需文件。您只需要添加并提交它们。
棠媳鳖
然后,我将还原不需要的更改,然后进行新的提交。
埃庐
,它将从另一个分支获取所有更改,并为您准备一个提交。 现在,删除所有不需要的更改,然后保留所需的更改。 git不会知道有合并。
吐兄
然后还原先前的提交:
然后添加您想要选择的文件/更改:
并提交:
注意提交哈希,我们将其称为PICK-SHA并返回到您的主分支,例如master强制结帐:
然后选择提交:
现在您可以删除temp分支:
勺的驴吓识
陈獭
它正是OP想要的。必要时它会解决冲突,类似
的处理方式。您所做的新更改不会
,但不会not50 not。
广躺椽
标记“ 52”指定了“ 53”的(第一个)父代。因此,此diff命令在提交
中选择对
所做的更改。 请注意,它不会提交任何内容(如
那样)。因此,如果您需要这样做,则必须执行以下操作: