我无法删除已消失的本地工作树分支。关键字是 local , worktree分支和 gone 。也就是说,问题Cannot delete a Branch that doesn't exist?与我的不匹配。
在调用git branch -d
之前尝试删除工作树文件夹时会发生这种情况。观察:
MINGW64 /d/Tmp
$ mkdir repoA
MINGW64 /d/Tmp
$ cd repoA
MINGW64 /d/Tmp/repoA
$ git init
Initialized empty Git repository in D:/Tmp/repoA/.git/
MINGW64 /d/Tmp/repoA (master)
$ echo a > a
MINGW64 /d/Tmp/repoA (master)
$ git add .
MINGW64 /d/Tmp/repoA (master)
$ git commit -a -m'added a'
[master (root-commit) 2cff3c3] added a
1 file changed, 1 insertion(+)
create mode 100644 a
MINGW64 /d/Tmp/repoA (master)
$ git worktree add -b branch-b ../repoB master
Preparing worktree (new branch 'branch-b')
HEAD is now at 2cff3c3 added a
MINGW64 /d/Tmp/repoA (master)
$ rm -rf ../repoB
MINGW64 /d/Tmp/repoA (master)
$ git branch -d branch-b
error: Cannot delete branch 'branch-b' checked out at 'D:/Tmp/repoB'
MINGW64 /d/Tmp/repoA (master)
$ git branch -d branch-b -f
error: Cannot delete branch 'branch-b' checked out at 'D:/Tmp/repoB'
MINGW64 /d/Tmp/repoA (master)
$ git --version
git version 2.19.1.windows.1
更新:
git worktree prune
可以删除工作树,但是branch-b
仍然存在:
$ git worktree list
D:/Tmp/repoA 2cff3c3 [master]
D:/Tmp/repoB 2cff3c3 [branch-b]
$ git worktree prune
$ git worktree list
D:/Tmp/repoA 2cff3c3 [master]
$ git branch -vv
branch-b 2cff3c3 added a
* master 2cff3c3 added a
如何删除我不再想要的branch-b
?