删除或撤消对远程Git仓库的推送 [英] Deleting or undoing a push to a remote Git repo

查看:178
本文介绍了删除或撤消对远程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

但我也会推荐将您的远程回购转换为裸回购

这篇关于删除或撤消对远程Git仓库的推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆