我有一个有很多分支机构的项目。
我想同时在几个分支上工作,而不用git checkout来回切换。
有没有办法我可以做,除了复制整个存储库在别的地方?
I have a project with many branches.
I would like to work on several branches simultaneously without switching back and forth with git checkout.
Is there any way I can do that besides copying the whole repository somewhere else?
最满意答案
Git 2.5+(2015年第二季度)将支持该功能:克隆了git repo后,您将能够使用新的命令git worktree add <path> [<branch>]检出不同路径中的多个分支。
它用更强大的机制替代了一个较旧的脚本contrib/workdir/git-new-workdir ,其中这些“链接”的工作树实际上记录在主要的repo new $GIT_DIR/worktrees文件夹中(以便在任何操作系统上工作,包括Windows )。
再次,一旦你克隆了一个repo(像/path/to/myrepo这样的文件夹),你可以在不同的独立路径( /path/to/br1 , /path/to/br2 )中添加不同分支的工作,那些与主要回购历史相关的工作树(不需要再使用--git-dir选项)
在“ Git多工作目录 ”中查看更多信息。
Git 2.5+ (Q2 2015) will support that feature: Once you have cloned a git repo, you will be able to checkout multiple branches in different path with the new command git worktree add <path> [<branch>].
That replaces an older script contrib/workdir/git-new-workdir, with a more robust mechanism where those "linked" working trees are actually recorded in the main repo new $GIT_DIR/worktrees folder (so that work on any OS, including Windows).
Again, once you have cloned a repo (in a folder like /path/to/myrepo), you can add worktrees for different branches in different independent paths (/path/to/br1, /path/to/br2), while having those working trees linked to the main repo history (no need to use a --git-dir option anymore)
See more at "Multiple working directories with Git?".
And once you have created a worktree, you can move or remove it (with Git 2.17+, Q2 2018).
更多推荐
发布评论