如何使用 Git 作为内容分发网络

发布于 2024-08-14 01:54:10 字数 281 浏览 6 评论 0原文

《Git Internal》一书提到在 p50 上使用 git 作为点对点内容分发网络,但没有提供太多细节。特别是如何拥有多个跟踪不同文件的分支。示例:(

工作目录) a00.exe a01.exe b00.exe c00.exe c01.exe c02.exe

主分支跟踪所有文件,而分支 A 只跟踪 a00.exe 和 a01.exe,分支 B 跟踪 b00.exe 等等。下一次提交将更新 a00.exe b00.exe c00.exe。如何创建这样的分支?提交所有分支后,我可以只从远程获取特定分支吗?谢谢!

The book 'Git Internal' mentions about using git as peer to peer content distribution network at p50, but doesn't have much detail. Especially how to have several branches which has tracking different files. Example:

(working dir)
a00.exe
a01.exe
b00.exe
c00.exe
c01.exe
c02.exe

Master branch tracks all files, while branch A only tracks a00.exe and a01.exe, branch B tracks b00.exe and so on. The next commit will update a00.exe b00.exe c00.exe. How to create branches like this? Once all branches committed, can I only fetch certain branch from remote? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2024-08-21 01:54:10

您将需要某种脚本来为您构建各个内容分支。执行此操作的基本方法是将内容添加到数据库(在您的情况下,只需将它们提交到主分支),然后在临时索引中,读取您想要在每个分支中拥有的所有内容(git read -tree/git update-index),写出该树(git write-tree),写入提交对象(git commit-tree)并将分支更新到该新提交(git update-ref)。这些都是日常操作中通常不使用的管道命令,但允许您构建快照,而无需同时将磁盘上目录中的所有内容包含在内。

执行此类操作的示例脚本如下:

http://github.com /schacon/gitcrazy/blob/master/update_content.rb

这里我定义了许多服务器,每个服务器都有一个或多个角色(“memcache”、“database”或“webserver”)。然后我可以将内容添加到这样的角色:

$ update_content.rb /path/to/content file_name memcache

这会将内容添加到我的 git db,然后更新受影响的服务器(在本例中具有 memcache 角色)的分支。我可以对任何角色的多个文件执行此操作,并且 git 将跟踪每个服务器应具有的内容。然后每个服务器都可以获取其特定分支(“server/s1”、“server/s2”等)。

我正在考虑很快做一个快速截屏视频来演示这一点 - 希望示例脚本有所帮助。它应该很容易运行并弄清楚发生了什么。在同一个项目中,有一个“列表”脚本,列出了哪个服务器分支上的内容。

You will need to have a script of some sort build the various branches of content for you. The basic way to do this is to add the content to the database (in your case, just by committing them to the master branch), then in a temporary index, reading in all the contents you want to have in each branch (git read-tree/git update-index), writing that tree out (git write-tree), writing a commit object (git commit-tree) and updating the branch to that new commit (git update-ref). These are all plumbing commands that are not normally used in day-to-day operations but allow you to build snapshots without having all the contents in a directory on disk at the same time.

An example script to do something like this is here:

http://github.com/schacon/gitcrazy/blob/master/update_content.rb

Here I define a number of servers that each have one or more roles ('memcache', 'database' or 'webserver'). Then I can add content to a role like this:

$ update_content.rb /path/to/content file_name memcache

That will add the content to my git db, then update the branches for the servers that are affected (that have the memcache role, in this case). I can do that for multiple files for any of the roles and git will keep track of what content each server should have. Then each server can fetch their specific branch ('server/s1', 'server/s2', etc).

I'm thinking of doing a quick screencast demonstrating this soon - hope the example script is helpful. It should be pretty easy to run and figure out what's going on. In the same project there is a 'list' script that lists out what content is on which server branch.

爱的故事 2024-08-21 01:54:10

git 内部结构作者 scott chacon 有一个关于该主题的视频/谈话,他谈到了某种商场中广告的内容分发网络。鼓舞人心: http:// www.techscreencast.com/language/ruby/using-git-in-ruby-applications---scott-chacon-/1431

There was a video/talk about that topic by the git internals author scott chacon, he talks about a content distribution network for ads in some kind of mall. inspiring: http://www.techscreencast.com/language/ruby/using-git-in-ruby-applications---scott-chacon-/1431

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文