Git - 将分支存储在单独的本地目录中
我对 git 相当陌生,正在尝试以正确的方式设置我的存储库。
基本上我的应用程序是一个平台,因此该平台的实现基于主分支,但对这些文件以及一些附加文件进行了一些小的修改。
我尝试将其设置为分支,因此我有一个 master
分支、implementation_1
和 implementation_2
。
但据我所知,这意味着本地所有分支都存储在一个目录中,它们的分离只能通过 git 进行。
我想要的是有 3 个本地目录,master
、imp_1
和 imp_2
。如果我对 imp_1
目录中的核心文件之一进行更改,我希望能够将该更改合并到 master
分支中,并从那里合并到 imp_2
。
我开始认为这些需要是 3 个不同的存储库(实现是核心的分支)。这是要走的路吗?那么,我该如何处理上述情况呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
分支是 Git 中的一等公民。它们不会像旧版 VCS(例如 SVN、CVS 等)那样“模拟”为分支。
如果您确实需要三个不同的目录,因为您想要拥有三个不同的开发环境,请创建 3 个克隆:
master 的目录中
imp_1
的目录中imp_2
的目录中但要真正理解分支,您可以阅读“DVCS 中不同分支模型的优缺点”。
或者,从 Git 2.5 开始(2015 年 7 月,OP 提出问题 4 年后),正如我在 Git 的多个工作目录?,使用
git worktree
。这将是一个克隆,多个文件夹(每个分支一个)。
使用 Git 2.7+,您可以列出这些文件夹:
Branches are first class citizens in Git. They are not "emulated" as branches like in older VCS such SVN, CVS, etc.
If you really need three different directories, because you want to have three distinct development environment, make 3 clones:
master
imp_1
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 detailed 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 中的分叉与分支的合并方式等没有什么不同。你可以轻松做到:
本地克隆时,git 会硬链接你的对象,甚至节省磁盘空间
you can create three clones of your repository and merge between those. forks in git are no different from branches the way they are merged and such. you can easily do:
when cloning locally git will hardlink your objects and even save disk space
您可以使用 git worktree 来完成此操作,该工作树是 于 2015 年 7 月左右在 Git 2.5 中引入。
瞧!你完成了。
通过此设置,您将只有一个 .git 文件夹(位于 master/.git 中)。请注意,一次可以在单个工作树中签出任何分支。
You can do this using git worktree that was introduced in Git 2.5, circa July 2015.
And voilà! You're done.
With this setup, you'll have only one .git folder (in master/.git). Note that any branch can be checked out in a single worktree at a time.