Search code examples
gitversion-controlbranchdvcsgit-branch

Applying specific commit(s) from one git repository on another


We are developing automation code that runs against multiple different versions of our company's products.

Per product version we're aiming to keep a dedicated code branch in Git.

Branches may diverge and contain different history, however for some commits which may be valuable for multiple product versions, we'd like to have the ability to apply them on other branches than the one they were made on.

I know one option that is used in the open source world is sending Patches across (creating patches and applying them on the target branch(es) ).

What are the possible ways to perform this operation? Is a Patch the only way?


Solution

  • What you are looking for is git cherry-pick.

    Given that you are in the repo where you would like some other repo's changes applied (say other/). After you have other added as a remote, you can

    $ git cherry-pick COMMIT
    

    where COMMIT is e.g. the hash or name of the commit from other you would like to apply.