git同时在两个分支上工作 [英] git working on two branches simultaneously
问题描述
我有一个有很多分支的项目。
我想同时在几个分支上工作而不用<$ $来回切换c $ c> git checkout 。
除了将整个资料库复制到其他地方之外,有什么办法可以做到吗? git 2.5+(Q2 2015)将支持该功能:一旦你克隆了一个git repo,你将能够检出多个不同的分支使用新命令的路径 git worktree add< path>替换旧脚本
contrib / workdir / git-new-workdir 。
/ code>,使用更强大的机制,这些链接工作树实际上记录在主要的仓库新建 $ GIT_DIR / worktrees
文件夹中任何操作系统,包括Windows)。
同样,一旦你克隆了一个回购库(在 / path / to / myrepo
),您可以为不同的独立路径( / path / to / br1
, / path / to / br2
),同时让那些工作树链接到主repo历史记录(不需要使用 - git-dir
选项)
详情请参阅 多个工作目录与Git? 。
一旦您创建了 worktree,你可以移动或移除它(使用Git 2.17+,Q2 2018)。
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+ (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).
这篇关于git同时在两个分支上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!