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

问题描述 投票:0回答:1

假设我有一个包含子模块的 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
git git-submodules git-worktree
1个回答
7
投票

您可以使用

--force
删除包含子模块的工作树:

git worktree remove --force <path-to-worktree-with-submodules>
© www.soinside.com 2019 - 2024. All rights reserved.