我正在为我的项目使用git和git-repo。我看到当我尝试使用git命令
删除我当前使用的本地分支时git branch -D branch_name
它显示了我期待的错误,因为我们无法删除当前分支。
但是如果我使用repo命令
repo abandon branch_name
我可以删除当前分支。所以我的问题是什么命令是repo使用内部删除分支?
答案 0 :(得分:4)
abandon.py
subcmd来电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)
换句话说,它确保不位于您要删除的分支上,即使这意味着设置detached HEAD(通过签出SHA1'{{1 }}“)。