2013-08-04 114 views
1

我想刪除遠程存儲庫上的兩個已損壞的提交。復位後顯示在git push中的錯誤--hard,致命錯誤非快進

我用:

git reset --hard <commit_id> 

這樣我就可以回到上次提交我想恢復。然後,我通過從外部文件夾(不在存儲庫中)粘貼修改過的文件來修改我所做的更改。

現在,當我回推到遠程存儲庫,它拋出一個錯誤:

$ git push origin master --force 
[email protected]'s password: 
stdin: is not a tty 
Total 0 (delta 0), reused 0 (delta 0) 
remote: error: denying non-fast-forward refs/heads/master (you should pull first 
) 
To ssh://[email protected]/repos.git 
! [remote rejected] master -> master (non-fast-forward) 
error: failed to push some refs to 'ssh://[email protected]/repos.git' 

但是,如果我再拉,老提交我使用Git復位刪除會回來。

我嘗試使用

git push origin master --force 

早,但它仍然無法正常工作。

我應該如何解決這個問題,以便我可以從遠程刪除提交,並將我的新文件追加到它?

謝謝!

~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~

UPDATE:

使用git push origin :master 這裏就是答案從qqx輸出

$git push origin :master 
stdin: is not a tty 
remote: error: By default, deleting the current branch is denied, because the next 
remote: error: 'git clone' won't result in any file checked out, causing confusion. 
remote: error: 
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to 

remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the 

remote: error: current branch, with or without a warning message. 
remote: error: 
remote: error: To squelch this message, you can set it to 'refuse'. 
remote: error: refusing to delete the current branch: refs/heads/master 
To ssh://[email protected]/repos.git 
! [remote rejected] master (deletion of the current branch prohibited) 
error: failed to push some refs to ssh://[email protected]/repos.git 
+0

你嘗試過'git push origin + master'嗎? – Hasturkun

+0

@Hasturkun使用'--force'選項相當於在用'+'推送每個分支前加上前綴,這樣對已經嘗試過的東西沒有任何影響。 – qqx

+0

@qqx:嗯,手冊沒有太明確 – Hasturkun

回答

4

你的遠程倉庫可能有receive.denyNonFastForwards設置中啓用了 其配置。通過做

If set to true, git-receive-pack will deny a ref update which is not a fast-forward. Use this to prevent such an update via a push, even if that push is forced. This configuration variable is set when initializing a shared repository.

您可以來解決這個問題:該選項狀態的文檔

git push origin :master 
git push origin master 

在第一命令的分支名領導冒號變成變成一隻 請求刪除遠程存儲庫上的分支。在完成之後, 推送當前版本的分支將不再被視爲 非快進推送。但是還有一個選項可以在 遠程存儲庫上設置,以防止刪除receive.denyDeletes

+0

從某種意義上說,我想實現的是用我的新提交覆蓋最後兩個提交。我能用這個實現嗎? – reikyoushin

+0

我添加了解決方案的輸出到問題中。 – reikyoushin

+0

如果允許刪除分支,這兩個命令基本上與強制推送相同。所以,是的,你可以從遠程刪除或替換提交。 – qqx