Git - 将分支存储在单独的本地目录中 [英] Git - Store branches in separate local directories

查看:387
本文介绍了Git - 将分支存储在单独的本地目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上我的应用程序是一个有点类似的平台,所以我的应用程序的实现这个平台是基于master分支,但对这些文件以及一些额外的文件做了一些小的修改。



我试着将它设置为分支,所以我有 master 分支, implementation_1 implementation_2



但据我所知,这意味着本地所有分支都存储在一个目录中,它们的分离仅通过git。



我想要的是有3个本地目录, master imp_1 imp_2 。如果我对 imp_1 目录中的某个核心文件进行了更改,我希望能够将该更改合并到 master 分支并从那里进入 imp_2



我开始认为这些需要是3不同的存储库(实现是核心的分支)。这是要走的路吗?在这种情况下,我将如何处理上述情况?

解决方案

分支是Git中的头等公民,不像以前的VCS那样模拟分支(SVN,CVS,...)如果你真的需要三个不同的目录,因为你想要三个不同的目录环境中,创建3个克隆:




  • 在名为 master

  • 一个放在名为 imp_2的目录中,名为 imp_1




但要真正理解分支,您可以阅读优点和缺点在DVCS不同分支模型






或者,从Git 2.5(2015年7月,OP问题后的4年)开始,详见使用Git的多个工作目录?,请使用 git worktree



这将是一个克隆,多个文件夹(每个分支一个)。

使用Git 2.7+,您可以列出这些文件夹:
$ $ $ $ $ g $ $ $ git worktree
$ / $ / $ / $ / $ / $ / linked-worktree abcd1234 [master]
/ path / to / other-linked-worktree 1234abc(detached HEAD)


I'm rather new to git, and am trying to set up my repository the right way.

Basically my app is a platform of sorts, so implementations of this platform are based on the master branch, but have some small modifications to those files as well as some additional files.

I tried setting it up as branches, so I have a master branch, implementation_1 and implementation_2.

But as far as I can tell, that would mean that locally all the branches are stored in one directory, with their separation being only through git.

What I would like is to have 3 local directories, master,imp_1, and imp_2. If I make a change to one of the core files in the imp_1 directory, I want to be able to merge that change into the master branch and from there into imp_2.

I'm beginning to think these need to be 3 different repositories (the implementations being forks of the core). Is that the way to go? In that case, how would I go about handling the above scenario?

解决方案

Branch are first class citizen in Git, meaning there are not "emulated" as branches like in older VCS (SVN, CVS, ...)

If you really need three different directories, because you want to have three distinct development environment, make 3 clones:

  • one in a directory called master
  • one in a directory called imp_1
  • one in a directory called imp_2

But to really understand branches, you can read "Pros and cons of different branching models in DVCS".


Or, since Git 2.5 (July 2015, 4 years after the OP's question), as I detailled in Multiple working directories with Git?, use git worktree.

That will be one clone, multiple folders (one per branch).
With Git 2.7+, you can then list those folders:

$ git worktree list
/path/to/bare-source            (bare)
/path/to/linked-worktree        abcd1234 [master]
/path/to/other-linked-worktree  1234abc  (detached HEAD)

这篇关于Git - 将分支存储在单独的本地目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆