关于如何做到这一点的任何想法?我知道我可以克隆NFS存储库并推送到它,但这似乎是不必要的过度杀伤.
它可以像在本地分区中创建.git符号链接到远程NFS分区中的.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 theGIT_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
orGIT_DIR
,or automatically discovered.
If--git-dir
orGIT_DIR
are specified but none of--work-tree
,GIT_WORK_TREE
andcore.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
” hascore.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 agit 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.