[英]git - how do I switch my app to use code from a different remote origin (not just a URL change, has different git history)
I had some intractable git-history related issues in my current (Rails) code repo, whose remote origin on Github is "V1.git"我在当前的(Rails)代码仓库中有一些棘手的 git-history 相关问题,它在 Github 上的远程源是“V1.git”
Thanks to help in another SO thread, I made an all-new repo with the issues fixed, and pushed the master branch of the new (fixed) repo to a new Github repo named "V2.git".感谢在另一个 SO 线程中的帮助,我制作了一个修复了问题的全新存储库,并将新(固定)存储库的主分支推送到了一个名为“V2.git”的新 Github 存储库。 FWIW, the files at the "HEAD" of both V1 and V2 are the same, but, if it matters, the most recent commit IDs are not the same and V2 also has a lot more git history. FWIW,V1 和 V2 的“HEAD”中的文件是相同的,但是,如果重要的话,最近的提交 ID 是不一样的,V2 也有更多的 git 历史记录。
How can I force-overwrite V2 from Github to my development folder MYAPP, while leaving all untracked files alone?如何将 V2 从 Github 强制覆盖到我的开发文件夹 MYAPP,同时保留所有未跟踪的文件?
I'm guessing I probably:我猜我大概是:
Or perhaps should I:或者我应该:
git init
然后做git init
git pull origin master
?那么像git pull origin master
这样的东西?Or perhaps it is as simple as adding "origin" to point to V2, then doing some sort of forced git-pull?或者它可能就像添加“原点”以指向 V2 一样简单,然后执行某种强制 git-pull 操作?
The step delete the .git folder
seems unnecessary. delete the .git folder
的步骤似乎没有必要。
But you'll probably want to backup your entire MYAPP folder first , as better safe than sorry.但是您可能想先备份整个 MYAPP 文件夹,这样安全总比抱歉好。
Then, a straightforward procedure would be:然后,一个简单的程序是:
git checkout master
git remote remove origin
git remote add origin git@github.com:YourLogin/V2.git # with the proper URL
git fetch origin
git reset --soft origin/master
# ↑ may suffice for your use case
# OR git reset --hard origin/master
# ↑ risk: overwriting unsaved changes or files untracked in V1 but tracked in V2
git branch -u origin/master
# ↑ optional: allows one to use `git push` and `git pull` without any argument
Then inspect the new repository state, with git status
or gitk
.然后使用git status
或gitk
检查新的存储库状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.