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

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

问题描述

我对 git 比较陌生,正在尝试以正确的方式设置我的存储库.

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.

我尝试将其设置为分支,所以我有一个 master 分支、implementation_1implementation_2.

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

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

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.

我想要的是有 3 个本地目录,masterimp_1imp_2.如果我对 imp_1 目录中的核心文件之一进行更改,我希望能够将该更改合并到 master 分支,然后再合并到 imp_2.

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.

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

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?

推荐答案

分支是 Git 中的一等公民.它们不像在 SVN、CVS 等旧版 VCS 中那样模拟"为分支.

Branches are first class citizens in Git. They are not "emulated" as branches like in older VCS such SVN, CVS, etc.

如果你真的需要三个不同的目录,因为你想拥有三个不同的开发环境,那就做3个克隆:

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

  • 在名为 master
  • 的目录中的一个
  • 位于名为 imp_1
  • 的目录中
  • 位于名为 imp_2
  • 的目录中

但要真正了解分支,您可以阅读DVCS 中不同分支模型的优缺点".

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

或者,正如我在使用 Git 的多个工作目录中详述的那样,自 Git 2.5(2015 年 7 月,OP 提出问题 4 年后)以来?,使用git worktree.

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

那将是一个克隆,多个文件夹(每个分支一个).
使用 Git 2.7+,您可以列出这些文件夹:

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天全站免登陆