Git - 将.git目录移动到另一个驱动器,将源代码保留在原来的位置 [英] Git - Moving the .git directory to another drive, keep the source code where it is
问题描述
我在一个小的快速ssd上有我的源代码和.git文件夹,我希望在我的第二个更慢的硬盘上有.git目录,并将我的工作代码保存在我的快速更小的ssd上,可以吗?怎么样?
谢谢。
我想我的本地工作副本.git目录会随着时间的推移而增长(使用新版本),因此,我更大的本地硬盘。工作副本的增长速度并不快,所以它在ssd上的敏感度越来越高。
另一个有趣的奖励是我将获得源代码(工作代码和.git回购)在2个差异驱动器,这是更多的保护笔记本电脑....
我使用Windows
是的,您可以
符号链接
您可以将 .git
dir符号链接(或使用交点)到不同的位置:
$ cd my / project
$ mv .git /over/here/.git
ln -s /over/here/.git。
储存库可以正常工作。
gitdir:
或者你可以用一个文件替换 .git
文件夹,告诉git .git
文件夹确实是。这正是默认 1.7.8或更高版本中设置git子模块的方式。
重新配置现有结帐的步骤如下:
- 移动.git dir到它需要的位置
- 将其替换为
.git
文件,其中包含:gitdir: path / to / .git
- 定义
core.worktree
指向工作副本
作为一个脚本:
$ cd my / project
$ mv .git /tmp/.git
$ echogitdir:/tmp/.git> .git
$ git config core.worktree $ PWD
Windows上的连接
使用 junction.exe
。
> junction.exe c:\ fast-ssd \proj\.git d:\slow-hdd\proj\.git
I have my source code and .git folder on a small fast ssd, I would like to have the .git directory on my second bigger slower hdd and keep my working code on my fast smaller ssd, is it possible? how? thanks.
I guess my local working copy .git directory will grow as time goes (with the new versions) and so it make sens to have it on my bigger local hdd. The working copy doesn't grow as fast so it makes sens on the ssd as it can compile faster.
The other interesting bonus is I will then have the source code (working code and .git repo) on 2 diff drives which is more protection for a laptop....
I'm using windows
Yes you can
Symlinks
You can symlink (or use junction points) the .git
dir to a different location:
$ cd my/project
$ mv .git /over/here/.git
ln -s /over/here/.git .
And the repository will work fine.
gitdir:
Or you can replace the .git
folder with a file that tells git where the .git
folder really is. This is exactly how git submodules are setup by default in version 1.7.8 or later.
The steps to re-configure an existing checkout are:
- move the .git dir to where it needs to be
- replace it with a file
.git
containing:gitdir: path/to/.git
- define
core.worktree
to point at the working copy
As a script that would be:
$ cd my/project
$ mv .git /tmp/.git
$ echo "gitdir: /tmp/.git" > .git
$ git config core.worktree $PWD
Junctions on Windows
Easily create junctions on Windows using junction.exe
from Microsoft.
> junction.exe c:\fast-ssd\proj\.git d:\slow-hdd\proj\.git
这篇关于Git - 将.git目录移动到另一个驱动器,将源代码保留在原来的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!