我對github整體比較陌生,所以有些解釋或者說的不是很清楚,見諒。
我曾經有一個名為“statictis”的檔案夾,它與一個名為“statictis 代碼檔案”的 github 存盤庫鏈接。包含鏈接到原始 github 的原始檔案的原始檔案夾現在不在我的本地計算機上。
最近,我創建了一些與我在 github 上的“statictis 代碼檔案”repo 相關的代碼檔案,但是因為我沒有鏈接到 repo 的原始檔案夾(我洗掉了它)。我正在嘗試找到一種將新代碼推送到舊倉庫的方法,但是因為鏈接到倉庫的原始檔案夾現在已經消失了,所以我被卡住了,我嘗試以通常的方式添加它:
git init
git remote add origin <remote link>
git add .
git commit -m 'New edit date/time'
git push origin master
我收到了這個錯誤:
! [rejected] master -> master (fetch first)
error: failed to push some refs to '*github repo link*'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我嘗試使用 pull 命令進行拉取:
git pull <remote> master:dev
git push origin master
但是我收到一個新錯誤,說我的分支落后了。所以我看到一個建議說使用 push -f,但這會洗掉我的提交。
如果您有任何建議提及。指導將不勝感激。
TL;博士:
- 鏈接到我本地機器上的 github 存盤庫的檔案夾現在已被洗掉。
- 我在一個完全不同的新檔案夾中有一些與 repo 主題相關的檔案,我正在嘗試將其推送到舊的 github repo,但它一直顯示錯誤。
uj5u.com熱心網友回復:
所以你創建了一個 repo 并且不小心丟失了本地或 github 中的檔案?如果您丟失了本地檔案,您可以再次將專案從存盤庫克隆到本地。
git clone https://github.com/github/training-kit.git
或者,如果您在本地進行了一些更改,并且您只洗掉了幾個檔案夾,您可以恢復所做的更改。
git checkout .或git restore .將還原所有本地未提交的更改。
然后更改 code_2 并將其推回 repo。讓我知道這種理解是否正確或修改您的問題,我也可以更新我的答案:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/476730.html
