Git仓库与git目录存储在其他地方 [英] Git repository with git directory stored elsewhere

查看:280
本文介绍了Git仓库与git目录存储在其他地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,如果这是重复的,我搜索了谷歌,所以找不到任何类似的东西,因为它是一个相当通用的搜索词集!


$ b $我想要的是让.git目录在工作树之外。



我需要这样做,因为它是一个隐藏的git仓库一个使用其他版本控制软件的项目,不幸的是,它的设置方式是在一个根目录下有多个项目(我希望每个项目都是git存储库),并且使用构建脚本来清除项目目录中的文件。到目前为止,我一直在对根目录进行版本控制,并忽略所有其他项目目录,因此其中一个项目是版本控制的,但我现在想要版本化另一个项目,并且显然不能在根目录中有多个git存储库(或者我可以?这将是一个很好的替代答案)。如果可能的话,将.git目录放在磁盘上的其他位置将是一个很好的解决方案。

解决方案

您可以指定git仓库显式地使用所有git命令的 - git-dir 全局选项。当你在 init 中使用这个选项时,它通常创建一个裸仓库,但是如果你提供 - work-tree 您可以使用分离工作树来初始化非裸仓库。

  git --git-dir = / var / repo / one.git --work-tree = / var / work / one init 

从此,你仍然需要提供 - git-dir 选项或设置 GIT_DIR 环境变量,以便git知道在哪里版本库是因为在工作树内没有任何git特定数据,但工作树将从git存储库配置中适当地确定。


I'm sorry if this is a duplicate, I've searched google and SO and couldn't find anything similar since it's a fairly generic set of words to search for!

What I want is to have the .git directory be outside of the working tree.

I need to do this because it's a 'stealth' git repository inside a project using other version control software, and unfortunately the way it is set up is with multiple projects (which I want to each be a git repository) inside one root directory, and with build scripts that like to purge files from the project directories. So far I've been versioning the root directory and ignoring all other project directories, so one of the projects was versioned, but I now want to version another project and clearly can't have multiple git repositories in the root directory (or can I? That would be a good alternative answer). Putting the .git directories elsewhere on disk would be a good solution, if it's possible.

解决方案

You can specify the path to the git repository explicitly with the --git-dir global option for all git commands. When you use this option with init it usually creates a bare repository but if you supply --work-tree as well you can initialize a non-bare repository with a 'detached' working tree.

git --git-dir=/var/repo/one.git --work-tree=/var/work/one init

From then on, you still have to supply either the --git-dir option or set GIT_DIR environment variable so that git knows where the repository is as there is no git specific data at all inside the working tree, but the working tree will be determined appropriately from the git repository config.

这篇关于Git仓库与git目录存储在其他地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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