Git 存储库路径在哪里创建?

发布于 2024-09-10 19:28:57 字数 332 浏览 4 评论 0原文

当使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

み青杉依旧 2024-09-17 19:28:58

您想要这样做有充分的理由吗?

当然,Git 使用 GIT_DIRGIT_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 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.

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.

无名指的心愿 2024-09-17 19:28:58

尽管默认为当前工作目录,但可以使用 GIT_DIR 环境变量或 --git-dir 命令行选项

--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:

--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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文