git同时在两个分支上工作(git working on two branches simultaneously)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
git同时在两个分支上工作(git working on two branches simultaneously)

我有一个有很多分支机构的项目。

我想同时在几个分支上工作,而不用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).

更多推荐

本文发布于:2023-04-20 16:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/6b62e6f5260a4b7dbbb30c821e622553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支   两个   工作   git   branches

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!