用本地仓库替换远程仓库,但保留远程仓库的提交历史记录 [英] replace remote repository with local repo, but keep commit history of remote
问题描述
我有一个Android存储在Github存储库中。现在我做了一个完整的应用程序重写(从另一个存储库中的新鲜事开始) - 如何将完整的新存储库推送到现有的存储库,但是保存它的提交历史记录?($)
我想我不想使用-f标志,因为提交被删除。最好的情况是拥有两个存储库的完整历史记录,但代码只能来自新的存储库。
这是一个暴力方法(假设您正在使用master分支):转到旧的原始回购,rm -Rf除.git目录外的所有内容。然后:
git add -u
git commit -m从头开始
$ b然后,在您当前的回购库中定义旧回购的远程设备:git remote add origRepo oldUrl
git fetch origRepo
然后,在您当前的回购中创建一个临时分支并推送您的代码:
$ bgit checkout -b tempBranch
git reset --hard origRepo / master
git merge master
git push origRepo tempBranch
然后在原始回购:
git fetch
git checkout master
git merge origin / tempBranch
git push origin master
如果不是每一个文件都需要被替换,你也可以使用我们的/他们的合并策略。
I have an Android "stored" in a Github repository. Now I did a complete rewrite of the app (started from fresh in another repository) - (how) is it possible to push the complete new repository to the existing one, but keeping it's commit history?
I guess I do not want to use the -f flag, as the commits are removed then. The best case would be to have the complete history of both repositories, but the code should only be from the new one.
解决方案Here's a brute-force approach (assuming you are working on the master branch):
Go to the old, original repo, rm -Rf everything but the .git directory. Then:
git add -u git commit -m "starting over"
Then, define a remote for the old repo in your current repo:
git remote add origRepo oldUrl git fetch origRepo
Then, create a temporary branch in your current repo and push your code:
git checkout -b tempBranch git reset --hard origRepo/master git merge master git push origRepo tempBranch
Then on the original repo:
git fetch git checkout master git merge origin/tempBranch git push origin master
You could also look into using an ours/theirs merge strategy if not every single file needs to be replaced.
这篇关于用本地仓库替换远程仓库,但保留远程仓库的提交历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!