文档章节

Git与IPFS的联合使用

openthings
 openthings
发布于 2018/01/17 16:05
字数 449
阅读 157
收藏 0

Git与IPFS的联合使用

Git, even more distributed

Have you ever said to yourself: "Man, my git server isn't distributed enough" or "I wish I had an easy way to serve a static git repository worldwide". Well wish no more, I have the solution for you!

In this article, I will be discussing how to serve a git repository through the ipfs network. The end result will be a git cloneable url served through ipfs!

To start, select a git repo you want to host, and do a bare clone of it:

$ git clone --bare git@myhost.io/myrepo

For those who aren't super git savvy, a bare repo means that it doesn't have a working tree, and can be used as a server. They have a slightly different format than your normal git repo.

Now, to get it ready to be cloned, you need to do the following:

$ cd myrepo
$ git update-server-info

Optionally, you can unpack all of gits objects:

$ cp objects/pack/*.pack .
$ git unpack-objects < ./*.pack
$ rm ./*.pack

Doing this breaks up gits large packfile into all of its individual objects. This will allow ipfs to deduplicate objects if you add multiple versions of this git repository.

Once youve done that, that repo is ready to be served. All thats left to do, is to add it to ipfs:

$ pwd
/code/myrepo
$ ipfs add -r .
...
...
...
added QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95 .

Now, all thats left is to try cloning it:

$ cd /tmp
$ git clone http://localhost:8080/ipfs/QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95 myrepo

Note: make sure to change out that hash for yours.

Now, you may be asking "well what good is a git repo that I can't change anything on?" Well let me tell you an awesome usecase! I tend to program in a language called Go, for those who don't know go uses version control paths for its imports, i.e:

import (
    "github.com/whyrusleeping/mycoollibrary"
)

This is a really nice feature, and solves a lot of problems, but often times, I run into the issue where im using someones library, and they change the API, and it breaks my code. Using what we've done above, you could clone the library, and add it into ipfs, so your import paths will now look something like:

import (
    mylib "gateway.ipfs.io/ipfs/QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95"
)

And you will be guaranteed to have the same code every time!

Note: Since go doesnt allow the usage of localhost for import paths, we use the public http gateways. This provides no security guarantees as a man in the middle attack could ship you bad code. You could use a domain name that redirects to the localhost instead to avoid the issue.

本文转载自:https://ipfs.io/docs/examples/example-viewer/example#../git/readme.md

上一篇: 基于IPFS建立网站
下一篇: IPFS 开发指南
openthings

openthings

粉丝 328
博文 1152
码字总数 698437
作品 1
东城
架构师
私信 提问
分布式文件系统--IPFS

IPFS 是分布式文件系统,寻求连接所有计算机设备的相同文件系统。在某些方面,这很类似于原始的 Web 目标,但是 IPFS 最终会更像单个比特流群交换的 git 对象。 IPFS = InterPlanetary Fil...

叶秀兰
2015/01/28
46K
3
Go IPFS 0.4.17-rc1 发布,文件系统 IPFS 的 Go 实现

Go IPFS 0.4.17-rc1 发布了,Go IPFS 是 IPFS 的 Go 实现版本。IPFS 是一个全局的、版本化的端到端文件系统。它结合了 Git、BitTorrent、Kademlia、SFS 和 Web 的优势,就像一个 bittorrent...

h4cd
2018/07/25
997
3
IPFS 服务的Python访问

IPFS 服务的Python访问 py-ipfs-api提供python api对IPFS服务通过http gateway进行访问,需要运行一个本地的IPFS daemon。https://github.com/ipfs/py-ipfs 是IPFS的纯Python语言实现,本身就...

openthings
2018/08/26
206
0
【IPFS专题#001】HTTP+git+BitTorrent=IPFS

一 HTTP+git+BitTorrent = IPFS 1 IPFS 是一个分布式文件系统(类似BitTorrent) 1.1 什么是文件系统 我们知道,买的电脑要装系统,就要对硬盘进行格式化,如果是windows系统, 我们通常格式...

xutaotao
2018/05/24
0
0
[实录001]IPFS:去中心化文件系统原理与实践

一、活动基本信息 题目: 【区块链联合技术工坊001期】IPFS:去中心化文件系统原理与实践 议题: 目标取代HTTP协议的超媒体协议IPFS到底是什么?它到底要解决HTTP的什么问题?它已经解决了哪...

区块链交流
01/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

入坑-双鹰咔哒C61016保时捷919赛车积木

原帖于ZDM首发 https://post.smzdm.com/p/amm53q8k/ 前几天 无意中逛ZDM 发现有条好价, C61016 标准版(无动力组件)狗东店家双十一活动, 原价249元, 现价219元, 还有199-100专享卷.到手119. ...

云逸清风
23分钟前
5
0
Centos7安装Redis5

一、安装gcc依赖 由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装 [root@localhost local]# yum install -y gcc  二、下载...

小致Daddy
24分钟前
5
0
软件开发和用户体验结合——Cresense和Symbio达成战略合作伙伴关系

软件开发和质量保证公司Symbio和用户体验设计机构Cresense达成战略合作伙伴关系。通过创新的软件开发和用户体验结合,打造以客户为核心的优质服务。 Symbio与Cresense已经合作多年。联合技术...

symbiochina88
30分钟前
5
0
Sass 简介

概念 Sass由hampton catlin设计,natalie weizenbaum于2006年开发,它可以免费下载和使用。 Sass是一个将脚本解析成CSS的脚本语言(SassScript),也是一款CSS预处理器,它减少了CSS的重复,...

凌兮洛
32分钟前
5
0
Java自学指南五、编码工具

工欲善其事,必先利其器... 想要高效率编码输出和快速处理文本,需要 熟悉编程语言的语法 盲打 至少需要熟练使用一种文本编辑器 至少熟练熟练使用一种 IDE (集成开发环境) 现实中,看到过二指...

ConstXiong
今天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部