简体   繁体   English

Git:如何创建带有指向Git主仓库的符号链接的本地仓库

[英]Git : How to Create local repo with symbolic links to the Git main repo

I would like to create a Git repo in which the users can only pull the files from the Git repository and can never push into it. 我想创建一个Git仓库,其中用户只能从Git存储库中提取文件,并且永远不会推入它。 Since this data cloned into the remote repo needed not be modified, I am thinking of creating soft links to the main repo to save space (data will be duplicated among many users). 由于克隆到远程仓库中的数据不需要修改,我想创建到主仓库的软链接以节省空间(数据将在许多用户之间重复)。

Can i create soft links in my local repo to the files in the remote repo when i do a Git clone? 当我执行Git克隆时,我可以在本地仓库中创建到远程仓库中的文件的软链接吗?

eg with some variation on git clone <path>/gitrepo . 例如,在git clone <path>/gitrepo .上有一些变化git clone <path>/gitrepo .

... where gitrepo is the main dir, and the command should create my local git repo with symbolic links pointing to the gitrepo. ...其中gitrepo是主目录,命令应该创建我的本地git仓库,其符号链接指向gitrepo。 The version control should be maintained. 应该维护版本控制。 Until i do a git pull, my local repo should be maintained, even if the main gitrepo has moved ahead. 直到我做一个git pull,我的本地回购应该保持,即使主要的gitrepo已经向前移动。 A git pull should recreate the symbolic links to point to the latest of the main repo. git pull应该重新创建符号链接以指向最新的主回购。

I am seeking to replace ln -s with a "version controlled ln -s " 我正在寻求用“版本控制的ln -s ”替换ln -s

Thanks, RB 谢谢,RB

Git does this automatically, when cloning locally. 当在本地克隆时,Git会自动执行此操作。 From the manpage of git clone : git clone的联机帮助页:

--local, -l

When the repository to clone from is on a local machine, this flag bypasses the normal "git aware" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. 当要克隆的存储库位于本地计算机上时,此标志会绕过正常的“git aware”传输机制,并通过制作HEAD副本以及对象和refs目录下的所有内容来克隆存储库。 The files under .git/objects/directory are hardlinked to save space when possible. .git/objects/directory下的文件是硬链接的,以便在可能的情况下节省空间。 This is now the default when the source repository is specified with /path/to/repo syntax, so it essentially is a no-op option. 现在,当使用/path/to/repo语法指定源存储库时,这是默认设置,因此它本质上是一个无操作选项。 To force copying instead of hardlinking (which may be desirable if you are trying to make a back-up of your repository), but still avoid the usual "git aware" transport mechanism, --no-hardlinks can be used. 强制复制而不是硬链接(如果你试图备份你的存储库,这可能是合乎需要的),但仍然避免使用通常的“git aware”传输机制,可以使用--no-hardlinks

Another interesting flag might be -s : 另一个有趣的标志可能是-s

--shared, -s

When the repository to clone is on the local machine, instead of using hard links, automatically setup .git/objects/info/alternates to share the objects with the source repository. 当要克隆的存储库位于本地计算机上而不是使用硬链接时,会自动设置.git/objects/info/alternates以与源存储库共享对象。 The resulting repository starts out without any object of its own. 生成的存储库在没有任何自己的对象的情况下开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM