如何将更改合并到单个文件中,而不是合并提交? [英] How do I merge changes to a single file, rather than merging commits?

查看:107
本文介绍了如何将更改合并到单个文件中,而不是合并提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支(A和B),我想将分支A中的单个文件与分支B中相应的单个文件合并。 解决方案

我遇到了同样的问题。确切地说,我有两个分支 A B ,它们具有相同的文件,但在某些文件中具有不同的编程接口。现在,分支 B 中的文件 f 的方法与两个分支中的接口差异无关, ,但这一变化对两个分支都很重要。因此,我需要将分支 B 的文件 f 合并到文件 f A



一个简单的命令已经解决了我的问题,如果我假设所有变更在两个分支 A B 中提交:

  git checkout A 

git checkout --patch B f

第一个命令切换到分支 A ,进入我要合并的位置 B 的s版本的文件 f 。第二个命令用 HEAD 中的 f 修补文件 f B 。您甚至可以接受/丢弃该补丁的单个部分。您可以在此处指定任何提交,而不必为 HEAD



社区编辑:如果文件 f 位于 B 并不存在于 A 上,然后省略 - patch 选项。否则,你会得到一个没有改变。消息。

I have two branches (A and B) and I want to merge a single file from branch A with a corresponding single file from Branch B.

解决方案

I came across the same problem. To be precise, I have two branches A and B with the same files but a different programming interface in some files. Now the methods of file f, which is independent of the interface differences in the two branches, were changed in branch B, but the change is important for both branches. Thus, I need to merge just file f of branch B into file f of branch A.

A simple command already solved the problem for me if I assume that all changes are committed in both branches A and B:

git checkout A

git checkout --patch B f

The first command switches into branch A, into where I want to merge B's version of the file f. The second command patches the file f with f of HEAD of B. You may even accept/discard single parts of the patch. Instead of B you can specify any commit here, it does not have to be HEAD.

Community edit: If the file f on B does not exist on A yet, then omit the --patch option. Otherwise, you'll get a "No Change." message.

这篇关于如何将更改合并到单个文件中,而不是合并提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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