问题
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.
回答1:
branch is currently checked out
That means your remote repo isn't a bare repo (i.e. 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.
回答2:
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.
来源:https://stackoverflow.com/questions/4883301/deleting-or-undoing-a-push-to-a-remote-git-repo