Git: Moving a commit between repositories

Posted Over 12 years ago. Visible to the public.

If you want to move a complete commit from one repository to another (and you don't want to add it as a remote), you can use these steps:

Create a patch

In the source repository, create a patch based on the commit by running

git format-patch SHA1_OF_COMMIT~..SHA1_OF_COMMIT # Note the ~
git format-patch HEAD~ # Shortcut for the latest commit

This will create a .patch file that describes this commit.

Apply the patch

In the target repository, restore the commit from the patch file with

git am -3way path/to.patch

Should this fail, you can fall back to only applying the diff. This way, you will need to create a new commit yourself.

git apply path/to.patch --reject

The parts that could not be applied cleanly end up in .rej files. Take care of those manually.


Also see Git: How to create and apply patches.

Tobias Kraze
Last edit
2 months ago
Dominik Schöler
Keywords
port
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2012-01-30 12:38)