# @adobe/git-server 中文文档

规范地址：https://npmcn.com/package/%40adobe/git-server/

版本：1\.3\.29
npm 元数据更新时间：2026-10-01T01:33:14.882Z
中文译文更新时间：2026-11-08T09:52:22.518Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40adobe/git-server
原文对照：https://npmcn.com/package/%40adobe/git-server/?lang=original
项目主页：https://github.com/adobe/git-server#readme
源码仓库：https://github.com/adobe/git-server

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：116 kB，22 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：15 个
- 首次发布：2018-07-05T14:18:50.743Z
- 最新版本发布：2021-09-20T12:22:33.132Z
- 近 30 天下载量：1820（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：203（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @adobe/git-server
```

也可以使用：`pnpm add @adobe/git-server`、`yarn add @adobe/git-server`、`bun add @adobe/git-server`

## README

# git 服务器

GitHub 协议和 API 仿真 .

-   [状态](https://npmcn.com/package/%40adobe/git-server/#readme-status)
-   [说明](https://npmcn.com/package/%40adobe/git-server/#readme-description)
-   [安装](https://npmcn.com/package/%40adobe/git-server/#readme-installation)
-   [开始](https://npmcn.com/package/%40adobe/git-server/#readme-getting-started)
    -   [1\. 创建本地 Git 仓库](https://npmcn.com/package/%40adobe/git-server/#readme-1-create-a-local-git-repository)
    -   [2\. 启动服务器](https://npmcn.com/package/%40adobe/git-server/#readme-2-start-server)
    -   [3\. 通过 http 获取 Git repo 文件的原始内容](https://npmcn.com/package/%40adobe/git-server/#readme-3-fetch-raw-content-of-file-in-git-repo-over-http)
-   [Git 协议和 APIs](https://npmcn.com/package/%40adobe/git-server/#readme-git-protocols-and-apis)
    -   [1\. Git Raw议定书](https://npmcn.com/package/%40adobe/git-server/#readme-1-git-raw-protocol)
    -   [2\. Git HTTP 转让协议](https://npmcn.com/package/%40adobe/git-server/#readme-2-git-http-transfer-protocols)
        -   [`git push` 支助](https://npmcn.com/package/%40adobe/git-server/#readme-git-push-support)
    -   [3\. GitHub API v3 (英语)](https://npmcn.com/package/%40adobe/git-server/#readme-3-github-api-v3)
    -   [4\. 类似 GitHub 的网络服务器](https://npmcn.com/package/%40adobe/git-server/#readme-4-github-like-web-server)

* * *

## 状态

[![codecov](https://img.shields.io/codecov/c/github/adobe/git-server.svg)](https://codecov.io/gh/adobe/git-server) [![CircleCI](https://img.shields.io/circleci/project/github/adobe/git-server.svg)](https://circleci.com/gh/adobe/git-server) [![GitHub license](https://img.shields.io/github/license/adobe/git-server.svg)](https://github.com/adobe/git-server/blob/main/LICENSE.txt) [![GitHub issues](https://img.shields.io/github/issues/adobe/git-server.svg)](https://github.com/adobe/git-server/issues) [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/adobe/git-server.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/adobe/git-server/context:javascript) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## 说明

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

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

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

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

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

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

目前支持以下协议和API:

-   [Git Raw 协议](https://npmcn.com/package/%40adobe/git-server/#readme-1-git-raw-protocol)
-   [Git HTTP 传输协议](https://npmcn.com/package/%40adobe/git-server/#readme-2-git-http-transfer-protocols)
-   [GitHub API v3 (英语)](https://npmcn.com/package/%40adobe/git-server/#readme-3-github-api-v3)

## 安装

```bash
cd <checkout dir>
npm install
```

## 开始

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

```javascript
{
  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` 用途 [螺旋标记](https://github.com/adobe/helix-log) 用于伐木。 日志级别( O)`fatal`, (中文(简体) ), `error`, (中文(简体) ), `warn`, (中文(简体) ), `info`, (中文(简体) ), `verbose`, (中文(简体) ), `debug`, (中文(简体) ), `trace`)可以通过 `logs.level` 属性在配置中(见上文)。 详情请查阅 [螺旋标记](https://github.com/adobe/helix-log) 项目.

### 1\. 创建本地 Git 仓库

```bash
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\. 启动服务器

```bash
npm start
```

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

```bash
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`

联合国

-   [10.6 地产内部-转让议定书](https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols)
-   [Git HTTP 运输协议文件](https://github.com/git/git/blob/master/Documentation/technical/http-protocol.txt)

#### `git push` 支助

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

```bash
git config receive.denyCurrentBranch updateInstead
```

[更多信息](https://stackoverflow.com/questions/804545/what-is-this-git-warning-message-when-pushing-changes-to-a-remote-repository/28262104#28262104)

### 3\. GitHub API v3 (英语)

联合国 [GitHub API v3 (英语)](https://developer.github.com/v3/)

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

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

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

-   [获取内容](https://developer.github.com/v3/repos/contents/#get-contents)
    
    _说明:_ GitHub 执行支持最多1兆字节的文件大小.
    
-   [滚开](https://developer.github.com/v3/git/blobs/#get-a-blob)
    
    _说明:_ GitHub 执行支持大小可达100兆字节的blobs.
    
-   [获取树](https://developer.github.com/v3/git/trees/#get-a-tree-recursively)
    
-   [获得承诺](https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository)
    
-   [获取归档链接](https://developer.github.com/v3/repos/contents/#get-archive-link)
    
    _说明:_ 此方法返回 a `302` 以下载寄存器的 tarball 或 zipball 存档. `git-server` 还支持非官方的 `https://codeload.github.com` 不限制速率且不改变方向的终点:
    
    -   `https://codeload.github.com/{owner}/{repo}/[zip|tar.gz]/main`
    
    相关问题/讨论: [#5 支持代码load.github.com](https://github.com/adobe/git-server/issues/5#issuecomment-403072428)
    

当地实例:

-   `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 是什么？

为 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 和提交记录判断。

