Git 存储库路径在哪里创建?
当使用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\”中查找要添加到存储库的文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要这样做有充分的理由吗?
当然,Git 使用
GIT_DIR
和GIT_WORK_TREE
环境变量(或相应的开关)完全支持不同的目录布局。这在(类似)服务器场景中非常有用,在这种场景中,用户除了通过拉动和推送之外不会与此类存储库进行交互 - f.ex。在基于 Git 的部署系统中。但默认布局是项目根目录下的 .git 目录中的存储库。您可以尝试解决这个问题,但您将不断地必须告诉您正在使用的所有工具有关它的信息。不方便;你会让自己的生活变得困难。
因此,除非您有可靠的技术原因(而不仅仅是偏好),否则我建议不要尝试这种方式。
Is there a good reason for which you want this?
Sure, Git fully supports different directory layouts, using the
GIT_DIR
andGIT_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.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.So unless you have a solid technical reason (rather than mere preference), I advise against trying to work this way.
尽管默认为当前工作目录,但可以使用
GIT_DIR
环境变量或--git-dir
命令行选项: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: