我想刪除遠程存儲庫上的兩個已損壞的提交。復位後顯示在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
你嘗試過'git push origin + master'嗎? – Hasturkun
@Hasturkun使用'--force'選項相當於在用'+'推送每個分支前加上前綴,這樣對已經嘗試過的東西沒有任何影響。 – qqx
@qqx:嗯,手冊沒有太明確 – Hasturkun