删除或撤消对远程Git仓库的推送
我创建了一个远程git仓库,然后从错误的本地仓库推入代码。
本地仓库很好,我只想删除我推送到远程的内容并重新开始。
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.
我试过 git push origin:master
但遇到错误:
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://.................
有没有简单的检查方法? 'check in'或'check in'(以及其他变体)不会产生相关结果。
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
这意味着您的 remote repo不是裸露的repo (即没有任何存储库工作树,意味着一个分支已经被检出)。此外,它会删除所有 master
分支!
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!
如果您有权访问远程仓库的服务器,您可以将主分支重置为 HEAD〜1
以便删除刚刚推送的内容(假设您是唯一推送该内容的人)。
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).
如果您没有直接访问权限,可以去一个正确的本地回购和强制推动正确的HEAD掌握:
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
但我也会推荐将您的远程回购转换为裸回购。