使用'git worktree'为多个工作目录使用git 2.5的工作流程 [英] work flow for using git 2.5 for multiple work directories using 'git worktree'
问题描述
对git来说很新,我想了解如何在一个github项目中为不同分支使用多个工作目录。
特别是我想要/需要在两个分支上工作 - 一个是'主',另一个是维护版本,比如维护/项目1。
计划是在Linux / Mint 17.2下运行这项工作。
另外,我想利用2.5中介绍的最新git worktree特性。
假设我有一个github账户,关闭主项目,并将克隆到〜/ user / myproject中的本地计算机。
现在,我不希望通过git贡献代码推动我所有的工作成果&测试将通过电子邮件传递给其他人,以便通过电子邮件进行修复 - 通过git进行测试可能会很好,但不一定要开始。
我看到的步骤我需要一组相应的git命令:
- 创建两个工作树
- 在这些树之间切换
- 保持树与上游主人保持同步
- 其他注意事项/特殊注意事项以这种方式工作。
解决方案
创建两个工作树
-
git clone https://github.com/someone/someproject.git
(这会给你目录<$在$
master
分支上的c $ c> someproject )
-
cd someproject; git worktree add ../someproject-devel devel
(这会给你目录
someproject-devel $ code> devel
分支,假设有这样一个分支)
$ b -
切换这些树
只需使用 cd
命令。
使两棵树与上游主人保持同步
在相应的目录下只需 cd
并运行 git pull
。首先在主工作树中执行此操作可能是最好的,但不是必需的(手册页没有具体说明这一点,我没有详细查看工作树的实现情况,如果存在问题,它只会是最优的使用空间,而不是功能)。
以这种方式工作的任何其他警告/特殊注意事项。
从手册页:
,并且对
子模块的支持不完整。不建议对超级项目进行多次
结账。
Being very new to git, I'm trying to get an overview of how to use multiple work directories for different branches off one github project. In particular I want/need to work on two branches - one the 'master' the other one a maintenance release, say maintenance/project1. The plan is to run the work under Linux/Mint 17.2. As well, I would like to make use of the latest git worktree features introduced in 2.5.
Assuming I have a github account, have forked my own fork off the main project and have cloned the fork to my local machine in ~/user/myproject.
As things stand now, I don't expect to contribute code via git push, all the results of my work & testing will be passed on to others for possible fixes via e-mail - doing it via git might be nice down the road, but won't be necessary to start.
What I see as the steps I would need a corresponding set of git commands for are:
- Creating the two work tree
- Switching between these trees
- Keeping both trees up-to-date with the upstream master
- any other cautions/ special considerations for working this way.
Creating the two work trees
git clone https://github.com/someone/someproject.git
(this will give you directory
someproject
on themaster
branch)cd someproject; git worktree add ../someproject-devel devel
(this will give you directory
someproject-devel
on thedevel
branch, assuming such a branch exists)
Switching between these trees
Just use the cd
command.
Keeping both trees up-to-date with the upstream master
Just cd
in the appropriate directory and run git pull
. Doing this in the main working tree first may be best, but is not required (the man page does not address this specifically, and I haven't looked into the worktree implementation in detail. If an issue existed it would only be one of optimal use of space, not functionality).
any other cautions/ special considerations for working this way.
From the man page:
Multiple checkout in general is still experimental, and the support for
submodules is incomplete. It is NOT recommended to make multiple
checkouts of a superproject.
这篇关于使用'git worktree'为多个工作目录使用git 2.5的工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!