2014-10-12 76 views
0

我張貼在askubuntu這個問題,但我沒有得到一個answer.I看見元this post,所以我想我會嘗試SO張貼。混帳,同步新的存儲庫

因此,我已經基於Github上的現有存儲庫初始化了一個git存儲庫。我正在啓動的項目與爲存儲庫列出的最新提交大不相同。

當我試圖執行器這組命令

git init 
git remote add origin https://github.com/account/repo 
git fetch origin 
git add -A 
git commit -m "message" 
git push origin master 

我收到以下錯誤:

To https://github.com/account/repo 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to 'https://github.com/account/repo' 
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. 

的事情是,我知道有這個倉庫和產地之間的差異,但我明確不想從存儲庫中獲取最新的更改。我想用這個倉庫中的修改來覆蓋Github上的更改。

有沒有辦法做到這一點?無論如何,即使出現快進錯誤也要強制推送?

感謝您的幫助或指導。

編輯:會亞當Dymitruk this question工作的答案,或執行上述命令的順序已經搞砸了他的方法?

+0

訪問舊項目歷史記錄如果您的目標是丟失原始回購的歷史記錄,並將其替換爲您在本地回購庫中的內容,爲何你首先從這個原始回購開始,而不是創建一個全新的回購? – 2014-10-12 06:55:48

回答

1

添加-f到您的混帳推行力推

git push -f origin master 

這將拋出任何現有主的歷史遠程倉庫了。

如果你想保留現有的歷史,然後

後備現有主分支,並重新命名新的分支爲別的,並推動這一來代替。 git push origin master:new_proj。然後git checkout new_proj。您現在可以通過「origin/master」和新項目通過new_proj

+0

所以這會強制推送,但不會影響提交歷史記錄的權利?我仍然能夠看到以前文件的舊更改? – Wold 2014-10-12 06:59:31

+0

「這會扔掉」,所以沒有。如果你想保留舊的歷史,你有幾個選擇。我會編輯。 – 2014-10-12 07:00:32

+0

此外項目是相關的,但它是一個複雜的情況。無論我嘗試方法二,但我得到一個使用錯誤。 – Wold 2014-10-12 07:08:34