分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

[Node.js] 2、利用node-git-server快速搭建git服务器

发布时间:2023-09-06 01:14责任编辑:苏小强关键词:jsNode

本文用到了node-git-server

1、检测本地git版本

该包的使用需要机器上本来就安装git,且git的版本大于等于2.7:

1 ╭─root@lt /home/workspace ?2 ╰─# git --version ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????129 ↵3 git version 2.7.4

 

2、利用npm安装包

 1 ╭─root@lt /home/workspace ??2 ╰─# npm install node-git-server 3 /home/workspace 4 └─┬ node-git-server@0.3.0 ?5 ??├─┬ http-duplex@0.0.2 ?6 ??│ ├── duplex-pipe@0.0.2 ?7 ??│ └── inherits@1.0.2 ?8 ??└── through@2.3.8 ?9 10 npm WARN enoent ENOENT: no such file or directory, open ‘/home/workspace/package.json‘11 npm WARN workspace No description12 npm WARN workspace No repository field.13 npm WARN workspace No README data14 npm WARN workspace No license field.

有警告可以先忽略~

3、编写example

cd ./node_modules/node-git-server/example/

编辑index.js

 1 const Server = require(‘node-git-server‘); 2 const repos = new Server(‘/tmp/repos‘); 3 const port = process.env.PORT || 80; 4 ??5 repos.on(‘push‘, (push) => { 6 ????console.log(‘push ‘ + push.repo + ‘/‘ + push.commit 7 ????????+ ‘ (‘ + push.branch + ‘)‘ 8 ????); 9 ????push.accept();10 });11 ?12 repos.on(‘fetch‘, (fetch) => {13 ????console.log(‘fetch ‘ + fetch.commit);14 ????fetch.accept();15 });16 ?17 repos.listen(port, () => {18 ????console.log(`node-git-server running at http://localhost:${port}`)19 });

4、运行

1 ╭─root@lt /home/workspace/node_modules/node-git-server/example ?2 ╰─# node index.js 3 node-git-server running at http://localhost:80

5、测试git服务器

由于我的git服务器是在aliyun上跑的,并且绑定了www.beautifulzzzz.com,所以我先在本地新建一个git仓库,并将其推送同步到云端,然后再clone下来来做测试:

可见将本地git仓库同步到云端和普通的git服务器没有区别,简直太简单方便了!!!

同样git clone也比较简单!

6、云端git仓库的位置

在index.js中我们指定git仓库存放在:const repos = new Server(‘/tmp/repos‘);目录下

登录远程服务器可以发现在/tmp/repos/目录下存在我们同步的git仓库:(其中beep.git是之前push的一个)

1 ╭─root@lt /tmp/repos ?2 ╰─# ls3 beautifulzzzz.git ?beep.git

:: 如果您觉得不错,请推荐给更多人,帮助他们更快地解决实际问题中的坑~


@beautifulzzzz智能硬件、物联网,热爱技术,关注产品博客:http://blog.beautifulzzzz.com园友交流群:414948975

[Node.js] 2、利用node-git-server快速搭建git服务器

原文地址:http://www.cnblogs.com/zjutlitao/p/7599781.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved