简体   繁体   English

Git远程目录的本地存储库

[英]Git local repository for remote directory

I cannot find the answer to this anywhere. 我在任何地方都找不到答案。 Is it possible to set up a local git repository for files on a webserver? 是否可以为Web服务器上的文件设置本地git存储库? I do not want to put the repo on the webserver because of a lack of space. 由于空间不足,我不想将回购放在网络服务器上。

It sounds like you want a repo stored locally, but you want its work tree to coincide with a tree of content served by your web server. 听起来好像您希望将存储库存储在本地,但是您希望其工作树与Web服务器提供的内容树重合。

There is not native support for this, but if you can map the underlying drive/directory that contains the content tree to a local path (ie treat it as a network shared drive) then you could make it work with git worktree 没有本机支持,但是如果您可以将包含内容树的基础驱动器/目录映射到本地路径(即,将其视为网络共享驱动器),则可以使其与git worktree

The details of setting the server up to share the content directory, and mapping that share locally, depend on OS (and maybe on your web daemon and how it's set up, though if it's just serving files from a local content directory then it shouldn't be an issue). 设置服务器以共享内容目录以及在本地共享的映射的详细信息取决于操作系统(也许取决于您的Web守护程序以及其设置方式,尽管如果它只是从本地内容目录中提供文件,则不应这样做)。成为一个问题)。

Note that when you add a worktree, git wants to see an empty directory to check out into. 请注意,当您添加工作树时,git希望看到一个空目录以便检入。 So you'll need a brief "outage window" during which the content tree can be empty. 因此,您需要一个简短的“中断窗口”,在此期间内容树可以为空。 The procedure might then look like this 该过程可能如下所示

# First, map the content tree to ./web-content
# ...

# Now initialize a repo
mkdir repo-init
cd repo-init
git init

# Import the web content into the repo; must be in outage window
mv ../web-content/* .
git add .
git commit

# Re-make the repo as a "mirror" to remove the default work tree
cd ..
git clone --mirror repo-init repo
rm -rf repo-init
cd repo
git remote remove origin

# Now check the content back out to the server
git worktree add ../web-content master

# outage window can now end

You now have a local repo that is tracking the files on the web server. 您现在有了一个本地存储库,该存储库正在跟踪Web服务器上的文件。 If you want to be able to pull (or push) to update the server, you'll have to configure appropriately (as you would if the repo were on the server). 如果您希望能够拉(或推)更新服务器,则必须进行适当的配置(就像回购在服务器上一样)。

Absolutely yes. 绝对没错。 The easiest way is to keep repository locally and just put code (only working directory) remotely using ftp/rsync. 最简单的方法是将存储库保留在本地,并使用ftp / rsync将代码(仅工作目录)远程放置。 That's it. 而已。 Your host do not need your repo. 您的房东不需要您的仓库。

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

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