我有两个分支(A和B),我想合并来自分支A的单个文件与来自分支B的相应单个文件。


当前回答

假设B是当前分支:

$ git diff A <file-path> > patch.tmp
$ git apply patch.tmp -R

注意,这只对本地文件应用更改。之后你需要做出承诺。

其他回答

假设B是当前分支:

$ git diff A <file-path> > patch.tmp
$ git apply patch.tmp -R

注意,这只对本地文件应用更改。之后你需要做出承诺。

我将这样做

Git format-patch branch_old..branch_new文件

这将为文件生成一个补丁。

在目标branch_old上应用补丁

去吧等等补丁

git checkout <target_branch>
git checkout <source_branch> <file_path>

下面的命令将 (1)比较文件的正确分支,以掌握 (2)交互式地询问您应用哪些修改。

git checkout --patch master <fn>

这使用git的内部扩散工具。 也许有一点工作要做,但是直截了当。

#First checkout the branch you want to merge into
git checkout <branch_to_merge_into>
    
#Then checkout the file from the branch you want to merge from
git checkout <branch_to_merge_from> -- <file> 
    
#Then you have to unstage that file to be able to use difftool
git reset HEAD <file> 

#Now use difftool to chose which lines to keep. Click on the mergebutton in difftool
git difftool

#Save the file in difftool and you should be done.