如果同时在多个版本之间修改代码,使用分支切换效率低下,可尝试使用工作树来来减少来回切换导致的诸多问题,缺点是可能会占用空间数量会成倍增加。
相关命令:
git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]] [-b <new-branch>] <path> [<commit-ish>]
git worktree list [-v | --porcelain [-z]]
git worktree lock [--reason <string>] <worktree>
git worktree move <worktree> <new-path>
git worktree prune [-n] [-v] [--expire <expire>]
git worktree remove [-f] <worktree>
git worktree repair [<path>…]
git worktree unlock <worktree>
假设存在work1,work2,work3分支
新建工作树
git worktree add ./work1 #在当前目录创建work1分支到work1子目录
git worktree add ./work2 work2 #在当前目录创建work2分支到work2子目录
git worktree add ../work3 work3 #在父目录创建work3分支到work3子目录,路径可以是任意任意位置
删除工作树
git worktree remove ./work1
git worktree remove ./work2
git worktree remove ../work2