如何删除包含子模块的Git工作树?

8
假设我有一个包含子模块的Git仓库。
$ mkdir main-worktree
$ cd main-worktree
$ git init
Initialized empty Git repository in /…/main-worktree/.git/
$ git submodule add https://github.com/octocat/Hello-World.git Hello-World
Cloning into '/…/main-worktree/Hello-World'...
remote: Enumerating objects: 13, done.
remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13
Receiving objects: 100% (13/13), done.
$ git commit -m 'Create submodule'
[main (root-commit) 66070b6] Create submodule
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 Hello-World

然后为该仓库创建另一个工作树(包含子模块的工作树):
$ git worktree add ../secondary-worktree
Preparing worktree (new branch 'secondary-worktree')
HEAD is now at 66070b6 Create submodule
$ cd ../secondary-worktree
$ git submodule update
Cloning into '/…/secondary-worktree/Hello-World'...
Submodule path 'Hello-World': checked out '7fd1a60b01f91b314f59955a4e4d4e80d8edf11d'

如何删除我刚创建的secondary-worktree?我尝试使用git worktree remove,但是出现了错误:
$ cd <path-to-main-worktree>
$ git worktree remove ../secondary-worktree
fatal: working trees containing submodules cannot be moved or removed
1个回答

11
您可以使用--force来删除包含子模块的工作树:

(原文链接)

git worktree remove --force <path-to-worktree-with-submodules>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接