# gt: General Translation CLI tool: gt git setup
URL: https://generaltranslation.com/zh/docs/cli/reference/commands/git-setup.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 为生成的翻译文件配置 Git 合并驱动。gt git setup 命令的 API 参考。

使用 `gt git setup`，可按结构化内容 (而非纯文本) 合并 `gt-lock.json` 和生成的 GTJSON 文件。

## 概览 [#overview]

```bash
npx gt git setup [options]
```

请在包含 `gt.config.json` 文件的 Git 工作树中运行此命令。

## 工作方式 [#how-it-works]

1. 查找当前 Git 工作树的根目录。
2. 在根目录的 `.gitattributes` 文件中，为 `gt-lock.json` 和已配置的 `files.gt.output` 模式添加合并驱动条目。
3. 在代码仓库的本地 Git 配置中注册这两个合并驱动。
4.  (可选) 设置 [`omitConfigIds: true`](/docs/cli/reference/config#omit-config-ids)，并移除已生成的配置 ID。

该命令会保留 `.gitattributes` 中的现有内容，仅追加缺失的条目，因此更改 GTJSON 的 `output` 路径后，可以重新运行该命令。

## 选项 [#flags]

| 参数                           | 描述                                                       | 类型        | 可选 | 默认值                                   |
| ---------------------------- | -------------------------------------------------------- | --------- | -- | ------------------------------------- |
| `-c, --config <path>`        | `gt.config.json` 的路径。                                    | `string`  | 是  | 自动解析                                  |
| `--dry-run`                  | 输出将要进行的文件和 Git 配置更改，但不实际写入。                              | `boolean` | 是  | `false`                               |
| `--omit-config-ids`          | 设置 `omitConfigIds: true`，并移除 `_versionId` 和 `_branchId`。 | `boolean` | 是  | `false`                               |
| `--driver-command <command>` | Git 调用已安装 CLI 时使用的命令。                                    | `string`  | 是  | 优先使用本地 `gt` 二进制文件，其次使用 `PATH` 中的 `gt` |

## 示例 [#example]

预览生成的属性和本地 Git 配置：

```bash
npx gt git setup --dry-run
```

应用该配置，并避免将生成的 ID 写入 `gt.config.json`：

```bash
npx gt git setup --omit-config-ids
```

如果 pnpm 项目未在本地安装 CLI，请指定 Git 调用它的方式：

```bash
npx gt git setup --driver-command "pnpm exec gt"
```

## 其他说明 [#notes]

* **交互式配置：** 如果尚未启用 `omitConfigIds`，交互式运行时会询问是否启用，默认为“是”。非交互式运行和试运行不会弹出提示；如需启用，请传入 `--omit-config-ids`。
* **GTJSON 冲突：** 对不同顶层键的修改会自动合并。如果两个分支对同一个键做了不同的修改，Git 会照常报告合并冲突。
* **Lockfile 冲突：** lockfile 驱动程序要求 `gt-lock.json` 为版本 2。如果 lockfile 是旧版本，请在合并前运行 [`gt translate`](/docs/cli/reference/commands/translate) 或 [`gt stage`](/docs/cli/reference/commands/stage) 重新生成。
* **作用范围：** 该命令通过 `git config --local` 写入合并驱动设置，因此每个克隆都需要单独运行一次初始化。

### 版本历史

| 版本        | 变更                                       |
| --------- | ---------------------------------------- |
| `2.14.53` | 新增 `gt git setup` 和结构化合并驱动，并支持在配置中省略 ID。 |

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
