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

非 Y 不嫁゛ 提交于 2019-12-08 10:47:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!