我有一個私人存儲庫github
(說「ProjectX」)。項目需求中途改變,這意味着代碼必須重寫。我不想失去已經在「ProjectX」上取得的進展,所以我做了以下操作:重命名回購和推新代碼
- 在本地存儲庫中將「ProjectX」更名爲「ProjectX_advanced」。
- 改名爲遠程起源,像這樣:
git remote rm origin
也改名GitHub上的項目。
git remote add origin [email protected]:user/ProjectX_advanced.git
這是成功的。執行在終端上git remote -v
結果如下:
origin [email protected]:user/ProjectX_advanced.git (fetch)
origin [email protected]:user/ProjectX_advanced.git (push)
我也能推修改以上信息庫。
3.在github上創建一個名爲「ProjectX」的新回購。
4.在我的本地存儲庫中創建一個名爲「ProjectX」的新項目。
5.它初始化混帳,像這樣:
git init
git add .
git commit -m "First commit" .
6.增加了一個新的遠程起源,像這樣:
git remote add origin [email protected]:user/ProjectX.git
如果我現在在命令行上做git remote -v
,我得到正確的遠程位置。
7.出現問題時,我現在嘗試在當地的回購將更改到GitHub庫有:
git push origin master
錯誤消息::看到
To [email protected]:user/ProjectX.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:user/ProjectX.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
我已經看到了一些以前的問題here和here和其他一些表明我需要執行git pull
併合並,然後才能推送這些更改。
我的問題:
1.如果我做了git pull
,我的新「ProjectX」將被我不需要的代碼覆蓋。我如何解決它?
2.我已將所有遙控器重新命名(git remote -v
的輸出如預期)。我錯過了重命名一些遙控器?
3.我該如何解決這個問題?
好的反饋,補充我自己的答案。 +1 – VonC