简体   繁体   English

git - 如何将我的应用程序切换为使用来自不同远程源的代码(不仅仅是 URL 更改,具有不同的 git 历史记录)

[英]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:我猜我大概是:

  • in MYAPP, delete the current remote "origin" (points to V1)在MYAPP中,删除当前远程“原点”(指向V1)
  • and also probably delete the .git folder,也可能删除 .git 文件夹,
  • then simply clone V2 into the existing MYAPP folder where it will leave untracked file alone?然后简单地将 V2 克隆到现有的 MYAPP 文件夹中,它将单独留下未跟踪的文件?

Or perhaps should I:或者我应该:

  • in MYAPP, delete the current remote "origin" (points to V1)在MYAPP中,删除当前远程“原点”(指向V1)
  • and delete the .git folder并删除 .git 文件夹
  • then add the new remote "origin" (points to V2)然后添加新的远程“原点”(指向 V2)
  • then do git init然后做git init
  • then something like 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 statusgitk检查新的存储库状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 git中两个不同的远程原点如何切换 - How to switch between two different remote origin in git 为什么我克隆的git历史与起源的历史不同? - Why is my cloned git history different from the origin's one? 如何在 git 中切换到不同的远程分支 - How to switch to a different remote branch in git git显示日志,状态,提交或其他回购,但远程来源具有正确的URL - git show log, status, commit or different repo but remote origin has correct url 如何从尚未推送到git的原始提交中删除文件更改? - How do I remove a file change from a commit that has not been pushed to origin in git? 如何在保留 git 历史记录的同时,在我不拥有的远程存储库下移动没有远程的仅本地 git 存储库? - How do I move a local only git repo that has no remote under a remote repo that I do not own while preserving the git history? 如何从历史上不同时间的多个提交制作git补丁? - How do I make a git patch from multiple commits at different points in history? 如何更改远程 Git 存储库的 URI (URL)? - How do I change the URI (URL) for a remote Git repository? 当我使用SSH时,我使用-i开关,我是否也需要为我的GIT遥控器做这个? - When I SSH I use the -i switch, do I need to do that for my GIT remote also? 改变git远程源 - Change git remote origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM