利用 git worktree 并行开发

一、什么是worktree? Manage multiple working trees attached to the same repository. A git repository can support multiple working trees, allowing you to check out more than one branch at a time. 管理连接到同一存储库的多个工作树。一个git仓库可以支持多个工作树,允许一次迁出多个分支。 二、为什么要用worktree? 场景:正在开发新的需求,这时候还需要对已提测功能的bug fixes 方法1:先stash正在开发的代码,再check out到原分支进行bug fixes 缺点:分支切换后需要重新pod install,然后xcode重建索引并重新编译,耗时耗力 方法2:clone两个仓库 缺点:.git目录会占空间,且两个仓库之间毫无关联,无法相互查看本地提交 方法3:git worktree 三、worktree的相关命令 ➜ worktree_test git:(develop) git worktree -h usage: git worktree add [<options>] <path> [<commit-ish>] or: git worktree list [<options>] or: git worktree lock [<options>] <path> or: git worktree move <worktree> <new-path> or: git worktree prune [<options>] or: git worktree remove [<options>] <worktree> or: git worktree unlock <path> 四、常用操作 1、添加一个worktree git worktree add ....

May 10, 2020 · Darren Ou