成功解决fatal: ‘xxx‘ is already used by worktree at ‘yyy\.git‘
·
成功解决fatal: 'xxx' is already used by worktree at 'yyy\.git'
目录
解决问题
fatal: 'xxx' is already used by worktree at 'yyy\.git'
我们在一个本地仓库的submodule中切分支的时候,报了如下的错误:

解决思路
这是因为Git 不允许我们两次check out到同一个分支。因为如果我们这样做了,然后去其中一个work-tree中创建了一个新的commit,当我们回到另一个work-tree时,同一个分支会出现有一个有新的commit,而另一个没有新的commit的情况,形成冲突。因此,Git不允许我们两次check out到同一个分支。
解决方法
如果我们确实已经移除了另一个work-tree的话,只需运行下面的指令
git worktree prune
让 Git 意识到这一点。运行完成后,我们就可以check out到期望的分支了:

如果我们还没有移除另一个work-tree,不要两次check out到同一个分支。
参考资料
1.'<Branch>' is already checked out at '</other/location>' in git worktrees - Stack Overflow
更多推荐
所有评论(0)