Skip to content

Instantly share code, notes, and snippets.

@biggers biggers/gist:9607312
Last active Aug 29, 2015

What would you like to do?


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.

for f in buildout.cfg templates/bin/ # versions.cfg
   echo git checkout --patch $B  $f
   git checkout --patch $B  $f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.