2010-09-24 146 views
17

我創建了一個git repo並用一些東西進行了更新。後來我爲這個項目創建了一個新目錄,併爲它初始化了新的git。現在我想推動更改並在回購中替換舊的。當我做git push origin master我得到如何取代git回購?

! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '[email protected]:Username/repo2.git' 
To prevent you from losing history, non-fast-forward updates were rejected 
Merge the remote changes before pushing again. See the 'Note about 
fast-forwards' section of 'git push --help' for details. 

我該怎麼辦?

+0

相關:http://stackoverflow.com/questions/8461528/replace-github-repo-while-preserving-issues-wiki-etc – 2015-11-18 12:47:20

回答

25

你只需要稍微用點力:

git push --force origin master

--force也可以縮寫爲-f

+2

如果一個人想要保持以前的提交,並只是從新的回購添加新的東西如何另一個提交? – Defozo 2016-08-29 14:43:48

+0

@Defozo,看到[這個答案](http://stackoverflow.com/a/41276328/3681880)。 – Suragch 2016-12-22 12:37:11