使用 repo 放弃和 git branch -D 删除分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16706075/
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
Deleting branch with repo abandon and git branch -D
提问by mrutyunjay
I am using git and git-repofor my project. I see when I try to delete my local branch which I am currently on using git command
我正在为我的项目使用 git 和git-repo。当我尝试删除我当前使用 git 命令的本地分支时,我看到了
git branch -D branch_name
It shows me error which I am expecting, as we can't delete current branch.
它显示了我期望的错误,因为我们无法删除当前分支。
But if I use repo command
但是如果我使用 repo 命令
repo abandon branch_name
I am able to delete the current branch. So my question is what command is repo using internally to delete the branch?
我可以删除当前分支。所以我的问题是 repo 在内部使用什么命令来删除分支?
回答by VonC
The abandon.pysubcmdcalls project.AbandonBranch, which includes:
该abandon.pysubcmd调用project.AbandonBranch,其中包括:
head = self.work_git.GetHead()
if head == rev:
# We can't destroy the branch while we are sitting
# on it. Switch to a detached HEAD.
#
head = all_refs[head]
revid = self.GetRevisionId(all_refs)
if head == revid:
_lwrite(os.path.join(self.worktree, '.git', HEAD),
'%s\n' % revid)
else:
self._Checkout(revid, quiet=True)
In other words, it makes sure to notbe on the branch you are deleting, even if that mean setting up a detached HEAD(by a checkout of a SHA1 'revid').
换句话说,它确保不在您要删除的分支上,即使这意味着设置一个分离的 HEAD(通过检查 SHA1 ' revid')。

