git worktree add
默认使用绝对路径,因此如果您在bash(Git For Windows'或WSL)中运行它,则路径将在Windows git上无效:
C:\code\worktree-repo>git status
fatal: Not a git repository: /mnt/c/code/original-repo/.git/worktrees/worktree-repo
您可以通过更新工作树.git
文件(而不是工作树的目录!)中的路径为相对路径来解决此问题:
C:\code\worktree-repo>type .git
gitdir: ../original-repo/.git/worktrees/worktree-repo
您还应该更新.git/worktrees/worktree-repo/gitdir
以使原始仓库中的Windows git知道如何找到工作树,但这并不那么重要(据我所知,它可以防止git worktree prune
删除它并从原始仓库中检出相同的分支)。