是否可以为现有配置指定新的本地 git 存储库位置?
Is it possible to specify new local git repository location for existing config?
默认情况下,我通常 运行 git init
并且在根目录中有本地存储库。我在一个小型 SSD 上存储和处理我的项目文件,但在同一台机器上有一个 BIG ol' SATA HD,但作用不大。我在想我应该开始实践将它用于每个项目的实际存储库。
编辑:
我的意思是我有目录结构:
SMALL-DRIVE > 我的项目 > .git > 存储库文件...
SMALL-DRIVE > 我的项目 > src > 开发文件...
虽然我希望保持第二个不变,但我想将第一个移动到
BIG-DRIVE > 存储库 > 我的项目 > .git > 存储库文件...
(或类似的东西)
一切都在同一台机器上,我推送到的远程存储库不会有任何变化。
我相信我可以通过git init
这条新项目的新路径(很确定我可以自己弄清楚),但是有没有办法更新现有配置以使用新路径?如果是这样,是否有一个命令可以移动存储库中的当前文件,或者我只是手动移动 .git 目录?
是的,你可以。
选项 1(首选):镜像
只需 运行 这些命令即可镜像存储库:
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
查看有关镜像的更多信息here
选项 2:手动克隆和推送
第一步是 git clone
将存储库复制到本地目录。
然后,您使用 git remote add <name> <url>
添加一个新的远程存储库
然后,您可以简单地git push <name> --all
将所有内容发送到那里
将新遥控器 git 添加到您的 Git 存储库
git远程添加源git@yourgit.repo
验证新的远程仓库
git 远程-v
[...] is there a way to update an existing config to use the new path?
如果我对你的问题的理解正确,你目前有一个小而快的 HD 存储库,你想
- 将存储库的
.git
目录移动到大而慢的 HD,
- 但在小而快的 HD 上保留回购协议的工作树。
我说得对吗?
在那种情况下,git init --separate-git-dir
正合您意。引用 git init
's man page:
--separate-git-dir=<git dir>
Instead of initializing the repository as a directory to either $GIT_DIR
or ./.git/
, create a text file there containing the path to the actual repository. This file acts as filesystem-agnostic Git symbolic link to the repository.
If this is reinitialization, the repository will be moved to the specified path.
因此,只需 cd
到您的存储库,然后 运行
git init --separate-git-dir <desired-location-on-big-and-slow-drive>
I believe I can pass git init
this new path for new projects [...]
正确。使用与上面相同的命令。
默认情况下,我通常 运行 git init
并且在根目录中有本地存储库。我在一个小型 SSD 上存储和处理我的项目文件,但在同一台机器上有一个 BIG ol' SATA HD,但作用不大。我在想我应该开始实践将它用于每个项目的实际存储库。
编辑:
我的意思是我有目录结构:
SMALL-DRIVE > 我的项目 > .git > 存储库文件...
SMALL-DRIVE > 我的项目 > src > 开发文件...
虽然我希望保持第二个不变,但我想将第一个移动到
BIG-DRIVE > 存储库 > 我的项目 > .git > 存储库文件... (或类似的东西)
一切都在同一台机器上,我推送到的远程存储库不会有任何变化。
我相信我可以通过git init
这条新项目的新路径(很确定我可以自己弄清楚),但是有没有办法更新现有配置以使用新路径?如果是这样,是否有一个命令可以移动存储库中的当前文件,或者我只是手动移动 .git 目录?
是的,你可以。
选项 1(首选):镜像
只需 运行 这些命令即可镜像存储库:
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
查看有关镜像的更多信息here
选项 2:手动克隆和推送
第一步是 git clone
将存储库复制到本地目录。
然后,您使用 git remote add <name> <url>
然后,您可以简单地git push <name> --all
将所有内容发送到那里
将新遥控器 git 添加到您的 Git 存储库
git远程添加源git@yourgit.repo
验证新的远程仓库
git 远程-v
[...] is there a way to update an existing config to use the new path?
如果我对你的问题的理解正确,你目前有一个小而快的 HD 存储库,你想
- 将存储库的
.git
目录移动到大而慢的 HD, - 但在小而快的 HD 上保留回购协议的工作树。
我说得对吗?
在那种情况下,git init --separate-git-dir
正合您意。引用 git init
's man page:
--separate-git-dir=<git dir>
Instead of initializing the repository as a directory to either$GIT_DIR
or./.git/
, create a text file there containing the path to the actual repository. This file acts as filesystem-agnostic Git symbolic link to the repository.If this is reinitialization, the repository will be moved to the specified path.
因此,只需 cd
到您的存储库,然后 运行
git init --separate-git-dir <desired-location-on-big-and-slow-drive>
I believe I can pass
git init
this new path for new projects [...]
正确。使用与上面相同的命令。