簡體   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)

我在當前的(Rails)代碼倉庫中有一些棘手的 git-history 相關問題,它在 Github 上的遠程源是“V1.git”

感謝在另一個 SO 線程中的幫助,我制作了一個修復了問題的全新存儲庫,並將新(固定)存儲庫的主分支推送到了一個名為“V2.git”的新 Github 存儲庫。 FWIW,V1 和 V2 的“HEAD”中的文件是相同的,但是,如果重要的話,最近的提交 ID 是不一樣的,V2 也有更多的 git 歷史記錄。

如何將 V2 從 Github 強制覆蓋到我的開發文件夾 MYAPP,同時保留所有未跟蹤的文件?

我猜我大概是:

  • 在MYAPP中,刪除當前遠程“原點”(指向V1)
  • 也可能刪除 .git 文件夾,
  • 然后簡單地將 V2 克隆到現有的 MYAPP 文件夾中,它將單獨留下未跟蹤的文件?

或者我應該:

  • 在MYAPP中,刪除當前遠程“原點”(指向V1)
  • 並刪除 .git 文件夾
  • 然后添加新的遠程“原點”(指向 V2)
  • 然后做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 statusgitk檢查新的存儲庫狀態。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM