问题
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.
回答1:
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
回答2:
Remote's aren't limited to another machine: If you have one repository at /repo1 and another at /repo2 you can copy commits from repo1 to repo2 by simply adding repo1 as a remote to repo2 using filesystem paths:
cd /repo2
git remote add repo1 /repo1
You can now fetch, pull, and cherry-pick commits from repo1 to repo2.
回答3:
Do you just need to push commits from one local repo to another local repo?
git remote add local /path/to/repo.git
git push local master
来源:https://stackoverflow.com/questions/42538057/how-do-i-move-local-unpushed-commits-from-a-corrupt-git-repository-to-another