@adobe/git-server

中文文档
1.3.29发布于 2021/09/20Apache-2.0CommonJS近 30 天下载 1820

为 http(s) 上的 git 存储器服务

中文使用文档
文档目录12 节
  1. 状态
  2. 说明
  3. 安装
  4. 开始
  5. 1. 创建本地 Git 仓库
  6. 2. 启动服务器
  7. 3. 通过 http 获取 Git repo 文件的原始内容
  8. Git 协议和 APIs
  9. 1. Git Raw议定书
  10. 2. Git HTTP 转让协议
  11. 3. GitHub API v3 (英语)
  12. 4. 类似 GitHub 的网络服务器

git 服务器

GitHub 协议和 API 仿真 .


状态

codecov CircleCI GitHub license GitHub issues Renovate enabled Language grade: JavaScript semantic-release

说明

git-server 向 Git 客户端提供本地 Git 寄存器的分级服务 http:// 财务报告和审定财务报表 https:// 协议.

git-server 期望本地 Git 寄存器( 或克隆或创建于 git init在本地文件系统中组织如下:

<repos_root_dir>/
├── <owner_1>/
│   └── <repo_1>
│   └── <repo_2>
├── <owner_2>/
│   └── <repo_1>
│   └── <repo_2>

或者,虚拟寄存器映射允许“挂载”寄存器独立于文件系统中的位置 <owner>/<repo> 等级。 配置示例 :

  virtualRepos: {
    owner1: {
      repo1: {
        path: './repo1',
      },
    },
    owner2: {
      repo2: {
        path: '/repos/repo2',
      },
    },
  },

仓库通过 git-server 可以像GitHub上的任何寄存器一样使用,即你可以克隆它们并把更改推向. 该寄存器内容可以使用您将用来请求在 GitHub 上管理的文件的 URL 模式访问 .

目前支持以下协议和API:

安装

cd <checkout dir>
npm install

开始

git-server 通过 config.js 在当前工作目录中存在的文件。 默认配置如下:

{
  appTitle: 'Helix Git Server',
  repoRoot: './repos',
  // repository mapping. allows to 'mount' repositories outside the 'repoRoot' structure.
  virtualRepos: {
    demoOwner: {
      demoRepo: {
        path: './virtual/example',
      },
    },
  },
  listen: {
    http: {
      port: 5000,
      host: '0.0.0.0',
    },
    /*
    // https is optional
    https: {
      // cert: if no file is specfied a selfsigned certificate will be generated on-the-fly
      // cert: './localhost.crt',
      // key: if no file is specfied a key will be generated on-the-fly
      // key: './localhost.key',
      port: 5443,
      host: '0.0.0.0',
    },
    */
  },
  subdomainMapping: {
    // if enabled, <subdomain>.<baseDomain>/foo/bar/baz will be
    // resolved/mapped to 127.0.0.1/<subdomain>/foo/bar/baz
    enable: true,
    baseDomains: [
      // some wildcarded DNS domains resolving to 127.0.0.1
      'localtest.me',
      'lvh.me',
      'vcap.me',
      'lacolhost.com',
    ],
  },
  logs: {
    level: 'info', // fatal, error, warn, info, verbose, debug, trace
    logsDir: './logs',
    reqLogFormat: 'short', // used for morgan (request logging)
  },
}

git-server 用途 螺旋标记 用于伐木。 日志级别( O)fatal, (中文(简体) ), error, (中文(简体) ), warn, (中文(简体) ), info, (中文(简体) ), verbose, (中文(简体) ), debug, (中文(简体) ), trace)可以通过 logs.level 属性在配置中(见上文)。 详情请查阅 螺旋标记 项目.

1. 创建本地 Git 仓库

cd ./repos
# create org
mkdir helix && cd helix
# initialize new git repo
mkdir test && cd test && git init
# allow to remotely push to this repo
git config receive.denyCurrentBranch updateInstead
# add a README.md
echo '# test repo'>README.md
git add . && git commit -m '1st commit'
cd ../../..

2. 启动服务器

npm start

3. 通过 http 获取 Git repo 文件的原始内容

curl http://localhost:5000/raw/helix/test/main/README.md

Git 协议和 APIs

1. Git Raw议定书

服务于 git repo 中的文件内容 .

所请求的文件由 :

  • {owner}: GitHub 组织或用户
  • {repo}: 仓库名称
  • {ref}: 基特参考
    • 分支名称(例如). main(中文(简体) )
    • 标记名称( 例如 ). v1.0(中文(简体) )
    • (完整或快手) 表示身份(例如. 7aeff3d(中文(简体) )

GitHub 網址 :

  • https://raw.githubusercontent.com/{owner}/{repo}/{ref}/path/to/file
  • https://github.com/{owner}/{repo}/raw/{ref}/path/to/file

当地 git-server URL :

  • http://localhost:{port}/raw/{owner}/{repo}/{ref}/path/to/file
  • http://localhost:{port}/{owner}/{repo}/raw/{ref}/path/to/file
  • http://raw.localtest.me:{port}/{owner}/{repo}/{ref}/path/to/file (使用通配符 DNS 域解析到 127.0.0.1(中文(简体) )

远程示例 :

  • https://raw.githubusercontent.com/adobe/git-server/main/README.md
  • https://github.com/adobe/git-server/raw/main/README.md

当地实例:

  • http://raw.localtest.me:5000/adobe/git-server/main/README.md
  • http://localhost:5000/adobe/git-server/raw/main/README.md
  • http://localhost:5000/raw/adobe/git-server/main/README.md

raw.githubusercontent.com 为某些文件类型(例如JavaScript、CSS、HTML)提供不正确的服务 Content-Type: text/plain 头曰. 第三方解决方案,比如 rawgit.com 解决这一问题. git-server 为有正确内容类型的文件服务.

2. Git HTTP 转让协议

支助 git clone, push, fetch

联合国

git push 支助

本地的回购需要要么是 赤线 还原( r)git clone --bare 或者说 git init --bare)或需要设置以下选项:

git config receive.denyCurrentBranch updateInstead

更多信息

3. GitHub API v3 (英语)

联合国 GitHub API v3 (英语)

GitHub 终点 : https://api.github.com/

本地端点 : http://localhost:{port}/api 或例如:. http://api.localtest.me:{port} (使用通配符 DNS 域解析到 127.0.0.1(中文(简体) )

只支持 GitHub API 的一个小子集 :

  • 获取内容

    说明: GitHub 执行支持最多1兆字节的文件大小.

  • 滚开

    说明: GitHub 执行支持大小可达100兆字节的blobs.

  • 获取树

  • 获得承诺

  • 获取归档链接

    说明: 此方法返回 a 302 以下载寄存器的 tarball 或 zipball 存档. git-server 还支持非官方的 https://codeload.github.com 不限制速率且不改变方向的终点:

    • https://codeload.github.com/{owner}/{repo}/[zip|tar.gz]/main

    相关问题/讨论: #5 支持代码load.github.com

当地实例:

  • http://api.localtest.me:5000/repos/adobe/git-server/contents/README.md?ref=main
  • http://api.localtest.me:5000/repos/adobe/project-helix/git/blobs/bf13fe66cbee379db6a3e4ebf0300b8bbc0f01b7
  • http://localhost:5000/api/repos/adobe/git-server/contents/README.md?ref=main
  • http://localhost:5000/api/repos/adobe/project-helix/git/blobs/bf13fe66cbee379db6a3e4ebf0300b8bbc0f01b7

4. 类似 GitHub 的网络服务器

(尚未执行)

终点 : https://github.com/

譬如说.

https://github.com/{owner}/{repo}, (中文(简体) ), https://github.com/{owner}/{repo}/blob/{branch}/path/to/file

版本与发布记录

@adobe/git-server 共发布 203 个版本,首次发布于 2018/07/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.29latest2021/09/205 年前
1.3.282021/09/195 年前
1.3.272021/09/035 年前
1.3.262021/08/225 年前
1.3.252021/08/075 年前
1.3.242021/07/175 年前

其他发布通道:experimental → 0.9.6-nodegit.1,next → 0.9.18-pre.37。

关于 @adobe/git-server 的常见问题

@adobe/git-server 是什么?

为 http(s) 上的 git 存储器服务

如何安装 @adobe/git-server?

在项目目录运行 npm install @adobe/git-server,或使用 pnpm add / yarn add / bun add。

@adobe/git-server 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__git-server 是否存在。

@adobe/git-server 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/git-server 可以商用吗?

@adobe/git-server 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/git-server 的下载量有多少?

根据 npm 官方下载统计,@adobe/git-server 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,820 次,日均约 61 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/git-server 还在维护吗?

最新版本 1.3.29 发布于 2021/09/20(5 年前);至今共发布 203 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/07/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。