Read more

Git: Moving a commit between repositories

Tobias Kraze
January 30, 2012Software engineer at makandra GmbH

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

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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.

Posted by Tobias Kraze to makandra dev (2012-01-30 13:38)