2017-08-11 39 views
0

我有個人的git存儲文件。我想用一個全新的項目替換現有的遠程主文件(在github或bitbucket上)(對同一個項目重新嘗試)。用一組全新的文件替換現有的個人回購主文件

我刪除了計算機上項目的現有文件夾。然後我爲新的嘗試創建了一個新文件夾和一些新文件。

如何使用這些新文件替換現有的遠程主服務器?

在新文件夾中,我做了git init,git add .git commit -m "a completely different attempt"。但是,我需要做什麼?我試着用git remote add origin [email protected]:username/repo.gitgit push origin master,但這給了一個錯誤消息(我試圖按照在錯誤消息中提出的建議,但只導致新的錯誤消息)...

回答

2

它有助於如果,當你問一個涉及錯誤消息的問題,即在問題中包含確切的錯誤消息。鑑於你正在做的(試圖用你的本地庫,以取代遠程倉庫的歷史)什麼,你希望看到以下錯誤:

To github.com:larsks/someproject.git 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]:larsks/someproject.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

這是因爲你試圖取代歷史,而而不是簡單地用一組新的變化來更新它。這不是你偶然想要的,因爲它會導致數據丟失(即項目的一些或全部歷史)。不過,這正是你想要的東西,所以你需要使用--force-f)選項:

git push -f 

應導致像其中:

[...] 
+ 2a49b3d...3d1e101 master -> master (forced update) 

另一種解決方案,當然是只是刪除並重新創建遠程存儲庫。

+0

這確實奏效:)當然,爲了好玩而在歷史上進行舊嘗試會很好,但這對我來說並不重要。謝謝! – EricC

+0

您可以將舊的歷史記錄保存在不同的分支中。 – larsks

相關問題