Git 存储库路径在哪里创建?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3320244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the Git Repository Path created?
提问by Source.Energy
When one creates a NEW repository with Git, does the path where the .git subdir is added have to be the SAME one as the path where the project files are (i.e. the files to be managed by Git)? Another way of asking the same question is: If I want to create a new Git repository, does the repository path always have to coincide with the respective project path, or can I create a repository directory in ANOTHER location and then have Git POINT to the project path? For instance, if my Project is in "F:\My Projects\Mother Goose\Gerber\", could I create a Git Repository in say "F:\My Repositories\Pointer Path\Gerber\"? and then tell Git to look in "\My Projects\Mother Goose\Gerber\" for the files to be added to the repository?
当使用 Git 创建新存储库时,添加 .git 子目录的路径是否必须与项目文件所在的路径(即要由 Git 管理的文件)相同?提出相同问题的另一种方法是:如果我想创建一个新的 Git 存储库,存储库路径是否必须始终与相应的项目路径一致,或者我可以在另一个位置创建一个存储库目录,然后将 Git POINT 指向项目路径?例如,如果我的项目在“F:\My Projects\Mother Goose\Gerber\”中,我是否可以在“F:\My Repositories\Pointer Path\Gerber\”中创建一个 Git 存储库?然后告诉 Git 在“\My Projects\Mother Goose\Gerber\”中查找要添加到存储库的文件?
回答by Aristotle Pagaltzis
Is there a good reason for which you want this?
你想要这个有充分的理由吗?
Sure, Git fully supports different directory layouts, using the GIT_DIR
and GIT_WORK_TREE
environment variables (or the corresponding switches). This is very useful in server(-like) scenarios, where users don't interact with such repositories other than by pulling and pushing – f.ex. in Git-based deployment systems.
当然,Git 完全支持不同的目录布局,使用GIT_DIR
和GIT_WORK_TREE
环境变量(或相应的开关)。这在服务器(类似)场景中非常有用,在这些场景中,用户除了通过拉和推之外不与此类存储库进行交互 – f.ex。在基于 Git 的部署系统中。
But the default layout is the repository in the .git
directory at the project root. You can try to work against that, but you will constantly have to tell all the tools you are using about it. It's not convenient; you'll be making life difficult for yourself.
但默认布局是.git
项目根目录中的存储库。您可以尝试反对这一点,但您必须不断地告诉您正在使用的所有工具。不方便;你会让自己的生活变得困难。
So unless you have a solid technical reason (rather than mere preference), I advise against trying to work this way.
因此,除非您有可靠的技术原因(而不仅仅是偏好),否则我建议不要尝试以这种方式工作。
回答by Mark Rushakoff
Although it defaults to the current working directory, the repository can be placed anywhere by use of the GIT_DIR
environment variable or the --git-dir
command line option:
尽管它默认为当前工作目录,但可以使用GIT_DIR
环境变量或--git-dir
命令行选项将存储库放置在任何位置:
--git-dir=<path>
Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.
--git-dir=<path>
设置存储库的路径。这也可以通过设置 GIT_DIR 环境变量来控制。它可以是当前工作目录的绝对路径或相对路径。