[英]git - how do I switch my app to use code from a different remote origin (not just a URL change, has different git history)
我在當前的(Rails)代碼倉庫中有一些棘手的 git-history 相關問題,它在 Github 上的遠程源是“V1.git”
感謝在另一個 SO 線程中的幫助,我制作了一個修復了問題的全新存儲庫,並將新(固定)存儲庫的主分支推送到了一個名為“V2.git”的新 Github 存儲庫。 FWIW,V1 和 V2 的“HEAD”中的文件是相同的,但是,如果重要的話,最近的提交 ID 是不一樣的,V2 也有更多的 git 歷史記錄。
如何將 V2 從 Github 強制覆蓋到我的開發文件夾 MYAPP,同時保留所有未跟蹤的文件?
我猜我大概是:
或者我應該:
git init
git pull origin master
這樣的東西?或者它可能就像添加“原點”以指向 V2 一樣簡單,然后執行某種強制 git-pull 操作?
delete the .git folder
的步驟似乎沒有必要。
但是您可能想先備份整個 MYAPP 文件夾,這樣安全總比抱歉好。
然后,一個簡單的程序是:
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
然后使用git status
或gitk
檢查新的存儲庫狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.