如何在 Git 中删除 origin/master

Atc*_*old 14 git

我无法origin/master从我的服务器中删除。不知道为什么。

我的终端截图

错误信息如下

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 acanzian@elab.ecn.purdue.edu:/export/home/a/elabshare/git/ID-check.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'acanzian@elab.ecn.purdue.edu:/export/home/a/elabshare/git/ID-check.git'
Run Code Online (Sandbox Code Playgroud)

不,我没有使用Github

小智 14

代替从服务器中实际删除 master,您可以像这样替换它:

git push origin otherbranch:master -f
Run Code Online (Sandbox Code Playgroud)

这将用 otherbranch 的内容替换 master,但它仍将在远程调用 master。然后你可以在本地以 master 身份签出 master。

  • +1。这是我可以删除remotes/origin/master 上错误的首次提交的唯一方法。 (2认同)

Sli*_*ban 11

有趣的事实:即使是远程存储库也在一个分支上。你被拒绝是因为你试图删除你的源当前“签出”的分支。

如果您可以直接访问 repo,您​​只需打开一个 shell 裸报告目录并使用 good oldgit branch来查看当前所在的分支源。要将其更改为另一个分支,您必须使用git symbolic-ref HEAD refs/heads/another-branch.

如果您使用的是 Github 或 Gitorious 之类的服务,则必须使用该工具为您提供的 UI 进行更改(有关如何在常用工具中执行操作,请参阅此答案)。