Search code examples
gitgit-cherry-pick

How do I move local, unpushed, commits from a corrupt git repository to another repository?


Normally I can move pushed commits to another repository using cherry-pick: I fetch the related branch from 'another' repository to my new repo and cherry-pick with commit's ID.

I want to do the same thing for local--unpushed--commits in a corrupt repository (something went wrong and I cannot push my changes, but I need to move them to another repo).

Is there any way to cherry-pick commits from the corrupt repo to another repo?

PS: Both repositories exist on the same machine.


Solution

  • Another possible method.

    cd repo1_path
    git format-patch -1 <commit> --stdout > /tmp/xxx.patch
    cd repo2_path
    git checkout <branch>
    git am /tmp/xxx.patch