使用repo abandon和git branch -D删除分支

时间:2013-05-23 05:13:19

标签: git git-repo

我正在为我的项目使用git和git-repo。我看到当我尝试使用git命令

删除我当前使用的本地分支时
git branch -D branch_name

它显示了我期待的错误,因为我们无法删除当前分支。

但是如果我使用repo命令

repo abandon branch_name

我可以删除当前分支。所以我的问题是什么命令是repo使用内部删除分支?

1 个答案:

答案 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 }}“)。

相关问题