agentleFS
28672032962867203296/hermes-agent/skills/devops/copybara/SKILL.md

copybara

Skill0 starsChanged 3 months agoMITView on GitHub

Google Copybara:跨仓库代码迁移与转换工具。将代码从一个仓库搬运到另一个,支持路径替换、文件过滤、保留历史。

The file

Files
SKILL.md

Google Copybara

概述

Copybara 是 Google 开源的跨仓库代码迁移工具(3226⭐),用于在多个 Git 仓库之间转换和搬运代码。无状态设计(状态存在目标仓库 commit 里),多个用户/服务可以共用同一份配置。

核心概念

概念说明
Origin源仓库(权威仓库)
Destination目标仓库
Transformations搬运时的代码转换(路径替换、文件移动、内容替换)
Workflow定义一次搬运的完整流程
Starlark配置文件语言(Python 方言,.bara.sky)

典型场景

  1. 机密→公开同步:内部仓库的代码脱敏后发布到 GitHub
  2. 公开→机密导入:拉取外部贡献回到内部仓库
  3. 一次性迁移:把项目从旧仓库搬到新仓库并保留历史
  4. monorepo 拆分:从大仓库提取子目录为独立仓库

安装

# 下载预编译 JAR(推荐,无需 Bazel)
# 从 https://github.com/google/copybara/releases 下载最新 snapshot

# 或从源码编译(需要 JDK 11 + Bazel)
git clone https://github.com/google/copybara.git
cd copybara
bazel build //java/com/google/copybara
bazel build //java/com/google/copybara:copybara_deploy.jar

配置示例

# copy.bara.sky
core.workflow(
    name = "sync_to_public",
    origin = git.github_origin(
        url = "https://github.com/mycompany/internal.git",
        ref = "main",
    ),
    destination = git.destination(
        url = "https://github.com/mycompany/public.git",
    ),

    # 只搬运特定目录
    destination_files = glob(["libs/open_source/**"], exclude = ["INTERNAL.md"]),

    authoring = authoring.pass_thru("bot <bot@mycompany.com>"),

    transformations = [
        # 替换路径引用
        core.replace(
            before = "//internal/libs/secret",
            after = "//public/libs/open",
            paths = glob(["**/BUILD", "**/*.bzl"]),
        ),
        # 移动目录
        core.move("libs/open_source", "libs/public"),
    ],
)

运行:

copybara copy.bara.sky

关键功能

  • 路径转换:core.move() 移动目录,core.replace() 替换内容
  • 文件过滤:glob(["pattern"]) + exclude 精确控制搬运范围
  • 作者映射:authoring.pass_thru() / authoring.map() 控制 commit 作者
  • 无状态:通过目标仓库 commit message 中的标签跟踪进度,无需本地数据库

替代工具

工具特点
JoshRust 项目用,Git 历史双向同步
fbshipitMeta 开发,已弃用
git-filter-repo轻量,单次导出场景
git subtreeGit 内置,双向同步能力弱

注意事项

  • 只支持 Git(Mercurial 实验性)
  • 配置用 Starlark,不是标准 Python
  • 需要 JDK 11,Java 生态
  • 预编译 JAR 最省事,比源码编译少一堆 Bazel 依赖
  • Google 内部重度使用,社区相对小

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.