2016-01-22 98 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分支
  • 一旦功能完成 - 审查改变,如果它是好的 - 合并它,掌握,如果不是 - 丢弃它(只是不合并)