Reference: http://stackoverflow.com/a/11593308
I have two branches A and B and, I want to merge branch A's single file with Branch B's corresponding file. How can I do that?
I have two branches A [master] 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 [master].
A simple command already solved the problem for me, if I assume that all
changes are committed in both branches A and B.
Switch into branch A [master], into where I want to merge the B version of the file f.
git checkout A [master]
Patch the file f with f of HEAD of B.
git checkout --patch B f
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.
B=n_uniq_bridges for f in buildout.cfg templates/bin/compile-one-api-xsds.sh.in # versions.cfg do echo git checkout --patch $B $f git checkout --patch $B $f done