如何在NFS分区和本地分区中的工作树中安装git存储库?

我的主目录位于文件服务器上的远程安装的NFS分区中,并且是常规备份的.我想让我的项目的git存储库位于我的主目录下(以便备份)但我希望我的工作树位于我的工作站的本地磁盘分区中(这样构建速度很快).未备份本地磁盘分区.

关于如何做到这一点的任何想法?我知道我可以克隆NFS存储库并推送到它,但这似乎是不必要的过度杀伤.

它可以像在本地分区中创建.git符号链接到远程NFS分区中的.git目录一样简单吗?

解决方法

你可以创建你的 Git仓库:

>工作树是本地磁盘分区上的当前路径
>但是使用–git-dir =< path>指定.git dir或$GIT_DIR环境变量并引用(备份)主目录中的路径.

git init命令考虑了$GIT_DIR环境变量:

If the $GIT_DIR environment variable is set then it specifies a path to use instead of ./.git for the base of the repository.

或者,您可以在家庭目录中创建您的仓库,但添加以下git配置:

core.worktree

Set the path to the root of the work tree.
This can be overridden by the GIT_WORK_TREE environment variable and the --work-tree command line option.
It can be an absolute path or a relative path to the .git directory,either specified by --git-dir or GIT_DIR,or automatically discovered.
If --git-dir or GIT_DIR are specified but none of --work-tree,GIT_WORK_TREE and core.worktree is specified,the current working directory is regarded as the root of the work tree.

Note that this variable is honored even when set in a configuration file in a “.git” subdirectory of a directory,and its value differs from the latter directory (e.g. “/path/to/.git/config” has core.worktree set to “/different/path“),which is most likely a misconfiguration.
Running git commands in “/path/to” directory will still use “/different/path” as the root of the work tree and can cause great confusion to the users.

OP增加:

Could it be as simple as creating a .git symbolic link in the local partition to the .git directory in the remote NFS partition?

至少,通过设置(如git-dir或core.worktree),可以实现相同的效果,而不依赖于特定于操作系统的功能,如符号链接(在每个操作系统上都不可用)

更新2018年(8年后):Tom Russell添加in the comments

It appears that the --separate-git-dir flag is now used to point to .git/ on the NFS server when initializing the repository on the local workstation (NFS client).
Subsequent behavior is odd,though: Changes committed on the NFS client don’t automatically propagate to the server,requiring a git checkout -- <file> on the server.

I subsequently figured out that a git reset --hard in the server repo after a commit in the client repo (or vice-versa) is the easiest way to bring a working directory up to date.

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...