git 为什么git不让我删除远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21255373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why will git not let me delete a remote branch
提问by Marius
I have a local repository that I want to mirror to the remote 'websrv'. This used to work fine until I deleted a local branch. Now when I do
我有一个本地存储库,我想将其镜像到远程“websrv”。这曾经很好用,直到我删除了一个本地分支。现在当我做
git push --mirror websrv
I get
我得到
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/ecoli-moments
To [email protected]:~/baki_tracking.git
! [remote rejected] ecoli-moments (deletion of the current branch prohibited)
The branch 'ecoli-moments' points to the same commit as master, local and remote.
分支 'ecoli-moments' 指向与 master、本地和远程相同的提交。
What can I do about this so that the remote branch will be properly deleted?
我该怎么做才能正确删除远程分支?
Update:
更新:
The remote repository is bare, I checked the directory on the server (the config file has bare=true).
远程存储库是裸的,我检查了服务器上的目录(配置文件有裸=真)。
回答by Jan Hudec
Even a bare repository has a current branch. It is the one that will be checked out by default when you clone the repository. Git does not want to delete it and is telling you why.
即使是一个裸仓库也有一个当前分支。它是在您克隆存储库时默认检出的那个。Git 不想删除它并告诉你原因。
The default branch is the special HEAD
reference. Modify it to point to something that is expected to always exist, or to point to a revision. See also How does origin/HEAD get set?.
默认分支是特殊HEAD
引用。修改它以指向预期始终存在的内容,或指向修订版。另请参阅如何设置 origin/HEAD?.
You'll have to change what HEAD points to manually using git symbolic-ref
(1)on the server.
您必须在服务器上使用git symbolic-ref
(1)手动更改 HEAD 指向的内容。
Or you can set the option mentioned in the error to false (git config receive.denyDeleteCurrent false
on the server); if it's just a backup (--mirror
is mostly appropriate only for backup), the default branch does not really matter.
或者您可以将错误中提到的选项设置为false(git config receive.denyDeleteCurrent false
在服务器上);如果它只是一个备份(--mirror
通常只适用于备份),那么默认分支并不重要。
回答by u1860929
This seems to be a non bare repository. If that is the case, any push operation to the checked out branch on non bare repo will not work, git doesn't allow that.
这似乎是一个非裸存储库。如果是这种情况,任何对非裸仓库上已检出分支的推送操作都将不起作用,git 不允许这样做。
So you essentially need to check out a different branch and then push to the repo.
所以你基本上需要检查一个不同的分支,然后推送到 repo。
From Jan's comment, A useful method is to check no branch at all, that is go to the state known as detached HEAD
where the HEAD
ref
points to specific revision rather than to a branch.
从一月的评论,一个有用的方法是检查根本没有分支,那就是去被称为状态detached HEAD
,其中HEAD
ref
点到具体的修订,而不是一个分支。
The advantage of this is that if you make more commits to different branches in future, you don't have to check out different branch every time this error is thrown.
这样做的好处是,如果您将来对不同的分支进行更多提交,则不必在每次抛出此错误时都检查不同的分支。
A better way to avoid this though, if you are doing this for backups only, is to use a bare reponext time onwards.
但是,如果您仅针对备份执行此操作,则避免这种情况的更好方法是下次使用裸存储库。