2016-01-22 51 views
1

我做了一些糟糕的提交到github上託管的項目。我使用github的bfg工具刪除了提交,然後推送給github,git克隆了我使用的各種本地機器上的項目。我的本地機器和github之間都是正常的。Git推 - 強制讓遠程主人丟棄錯誤的提交?

但是,我部署到仍包含錯誤提交的遠程。當我這樣做:

git push remote master 

我得到這個錯誤:

! [rejected]  master -> master (fetch first) 
error: failed to push some refs to '[email protected]:blah/blah.git' 
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. 

當我這樣做:

git push --force remote master 

一切收益作爲預期;不過,我必須每次都這樣做。有沒有辦法告訴git覆蓋遠程的主機,以便它在不克隆的情況下丟棄錯誤提交?

+0

你試圖做錯誤的建議和運行'git拉.. .'?這個錯誤意味着你在本地沒有新的東西。 –

+0

問題是,遠程端的「新」提交是不好的,需要丟棄。我不希望他們合併。 –

回答

-1

如果您只是向您的遠程存儲庫添加新的提交,您可以git push remote master用您的本地新提交更新您的遠程回購。但是,如果您不僅僅添加新提交,而且還刪除或刪除更新其中一些,您不允許git push。在這種情況下,您需要使用git push --force remote master來替換(而不是更新)您本地的遠程提交歷史記錄。

0

的錯誤意味着你必須在遠程端新的東西你沒有在本地,並根據您的評論:

The problem is that the "new" commits on the remote side are bad and need to be discarded. I don't want them merged.

在這種情況下--force是覆蓋「壞」的唯一途徑提交。

但這也意味着你使用錯誤的git工作流程。你永遠不應該得到這些「壞」的承諾上主,如果你不喜歡這樣寫道:

  • 爲每個新特徵的新的分支,做發展存在,從來沒有直接提交到master分支
  • 一旦功能完成 - 審查改變,如果它是好的 - 合併它,掌握,如果不是 - 丟棄它(只是不合並)