这是服务器上的远程Git存储库
[aaa@web48 proj.git]$ git ls-remote .
dfca707432eb53678b37026b160a4bdc7f1ac6c3 HEAD
dfca707432eb53678b37026b160a4bdc7f1ac6c3 refs/heads/master
1e09c37443ee758644a712e3c1a8b08b18a1f50d refs/heads/placeholder
我想删除HEAD / master分支。如何在服务器上或远程执行此操作?我正在使用Tower客户端。
HEAD
远程裸仓库中的符号引用表示该仓库的默认分支。该仓库的所有非裸露克隆都将在克隆之后自动检出该分支。
因为它是默认设置,所以您不能像通常那样删除它,Git不会让您:
$ git push origin --delete 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 c:/Users/Keoki/Documents/GitHub/bare
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'c:/Users/Keoki/Documents/GitHub/bare'
上面的错误消息指出,您HEAD
仍然可以绕过安全检查来删除远程站点中的当前分支,但是我将向您展示如何更改默认分支,以便您仍可以保留默认分支,但master
可以按照自己的意愿删除。
如果可以访问远程仓库,则可以更改远程仓库中默认分支的内容。如果您使用的是GitHub或Bitbucket之类的托管服务提供商,则应允许您通过其Web界面更改默认分支。
因此,如果您有权访问遥控器,请使用以下命令更改符号引用HEAD
指向的分支:
git symbolic-ref HEAD refs/heads/<newDefaultBranch>
正如我在上一节中已经提到的,HEAD
如果您使用托管提供(例如GitHub或Bitbucket),则可以通过Web界面更新远程仓库中的默认分支。
转到存储库的“设置”标签,您将在顶部看到默认的分支设置,
进入仓库的“设置”标签,您会在中间附近看到默认的分支设置,
一旦更新了远程裸仓库中的默认分支,就需要更新该仓库的本地克隆认为HEAD
远程中的默认分支指向的位置。你可以这样做
git remote set-head <remote> --auto
# Or shorter
git remote set-head <remote> -a
您可以使用以下方法确认本地存储库已正确更新
$ git branch -r
origin/HEAD -> origin/foo
origin/foo
origin/master
现在,您已将HEAD
远程服务器上的默认分支更改为不同于master分支,然后就可以将其删除了,
$ git push origin --delete master
To c:/Users/Keoki/Documents/GitHub/bare
- [deleted] master
# Older syntax
$ git push origin :master
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句