将一些git提交移到新的回购站中 [英] Move some git commits into a new repo
问题描述
我使用这个 rest-more 存储库,其中包含许多web-api实现(如Facebook或Linkedin)。我分叉了该存储库,并在我的分支中添加了我自己的另一个web api实现。
但是现在我发现很难更新原始存储库。每次原始存储库更改时,我都重新分配我的分支,这非常繁琐。所以我想将我自己的实现分割成独立的存储库。
我的所有提交都在我的分支中组合在一起。只有一个提交触及原始存储库中的文件。
有没有简单的方法将我的提交移动到新的存储库中?我想这样做,这样我就可以保存我的提交历史记录。
我首先打开一个新的存储库:$ / $> $ / $> $ / $> git init新回购
然后,我将分支推送到该存储库:
cd rest-more
git push ../new -repo / my_branch
cd ../new-repo
git co my_branch
我创建了一个新的空初始提交:
git checkout --orphan newroot
git commit - -allow-empty -m'root commit'
然后我重新分配我的分支到这个起点,使用交互式标志只选择我的提交:
git rebase --onto newroot --root my_branch -i
需要在途中解决冲突,最后我最终得到一个只有我提交的库。
(可能有待改进,请随时提出建议。)
I am using this rest-more repository, which contains many implementations of the web-api (such as Facebook or Linkedin). I forked that repository, and in my branch I added my own implementation of another web api.
However now I find that it is pretty hard to keep updated with the original repository. I rebase my branch every time the original repository changes, which is pretty tedious. So I want to split out my own implementation to a standalone repository.
All my commits are in my branch grouped together. Only one commit is touching a file from the original repository.
Is there an easy way to move my commits into a new repository? I want to do this so I can preserve my commit histories.
I first open a new repository:
git init new-repo
I then pushed my branch to that repository:
cd rest-more
git push ../new-repo/ my_branch
cd ../new-repo
git co my_branch
I created a new empty initial commit:
git checkout --orphan newroot
git commit --allow-empty -m 'root commit'
Then I rebase my branch to this starting point, use interactive flag to pick only my commits:
git rebase --onto newroot --root my_branch -i
Need to resolve conflicts on the way, and finally I end up with a repository with only my commits.
(There are probably improvements to be made. Feel free to suggest anything.)
这篇关于将一些git提交移到新的回购站中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!