Deleting or undoing a push to a remote Git repo

I created a remote git repository and proceeded to push code to it from the wrong local repo.
The local repo is fine I just want to remove the content I pushed to the remote and start over.

I have tried git push origin :master but got an error:

! [remote rejected] master (branch is currently checked out)
error: failed to push some refs to 'ssh://.................

Is there a simple way of checking it in? 'check in' or 'checking in' (and other variations) produce no relevant results.


branch is currently checked out

That means your remote repo isn't a bare repo (ie a repository without any working tree, meaning a branch has been checked out). Plus that would remove the all master branch!

If you have access to the server where your remote repo is, you could reset the master branch to HEAD~1 in order to remove what has just been pushed (assuming you are the only person to push to it).

If you haven't a direct access, you can go to a correct local repo and force push that correct HEAD to master:

git push origin HEAD --force

But I would also recommend converting your remote repo to a bare repo.


What you tried to do would delete the branch head, not the commits. Definitely not what you want. However, deleting central commits is a BAD idea. Use "git revert" instead.

链接地址: http://www.djcxy.com/p/8642.html

上一篇: 如何将本地Git存储库推送到另一台计算机?

下一篇: 删除或撤消对远程Git仓库的推送