Search code examples
gitcherry-pickgit-cherry-pick

How to cherry-pick changes from one file to another file?


I have two files called vvn.c and aqu.c I did changes to vvn.c and I have that commit in my git. How to cherry-pick the same changes to aqu.c The only difference is the API's.

vvn.c contains API's as vvn_function_names()

whereas aqu.c contains API's as unions_function_names()

I don't know how to do that. I know about cherry-picking into the same file. Is there any way to do that?


Solution

  • Not exactly cherry-pick, but you might want to use:

    git checkout <branch or sha of commit> -- filename

    This checkouts the file by its version in another branch; it is the easiest possible solution, if it satisfy your needs (i.e., if you don't need to actually merge changes to the file from two separate branches)

    The other possibility is to generate diff (you can generate diff from a range of commits just and limit it to one file) and then apply the diff. Check out: How to diff the same file between two different commits on the same branch?