obsidian-gh-knowledge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Obsidian GitHub Knowledge

Obsidian GitHub 知识库

Use this skill to operate on a remote Obsidian vault stored in a GitHub repository without relying on local filesystem edits.
This skill should NOT guess which repo is your vault.
If the user does not provide
--repo
, require the user to either:
  • Provide
    --repo <owner/repo>
    explicitly, or
  • Set up the local config file described below, then use its
    default_repo
    .
使用本技能操作存储在GitHub仓库中的远程Obsidian库,无需依赖本地文件系统编辑。
本技能不会猜测哪个仓库是你的库。
如果用户未提供
--repo
,需要求用户执行以下操作之一:
  • 明确提供
    --repo <owner/repo>
    ,或
  • 配置以下本地配置文件,然后使用其中的
    default_repo

Practical Tips (Paths & Emoji)

实用技巧(路径与表情符号)

  • Always wrap
    --path
    values and file paths in quotes (emoji and spaces are common).
  • Prefer copy/pasting the exact
    path
    returned by
    list
    /
    search
    instead of hand-typing emoji segments.
  • Treat URL-encoded emoji in API output (e.g.,
    %EF%B8%8F%E2%83%A3
    ) as normal.
  • If you get
    HTTP 404
    , assume the path is wrong or the file does not exist; verify with
    list
    or
    search
    .
  • 始终用引号包裹
    --path
    值和文件路径(表情符号和空格很常见)。
  • 优先复制粘贴
    list
    /
    search
    返回的精确
    path
    ,而非手动输入含表情符号的部分。
  • 将API输出中的URL编码表情符号(如
    %EF%B8%8F%E2%83%A3
    )视为正常内容。
  • 如果收到
    HTTP 404
    错误,假设路径错误或文件不存在;使用
    list
    search
    进行验证。

SAFETY RULES (CRITICAL)

安全规则(至关重要)

These rules prevent accidental data loss. NEVER bypass them.
这些规则可防止意外数据丢失。绝不要违反它们。

1. NEVER Force Push to Main

1. 绝不要强制推送到Main分支

bash
undefined
bash
undefined

FORBIDDEN - This can delete all files

禁止操作 - 这会删除所有文件

gh api -X PATCH repos/.../git/refs/heads/main -F force=true
gh api -X PATCH repos/.../git/refs/heads/main -F force=true

FORBIDDEN - Direct reset

禁止操作 - 直接重置

git push --force origin main
undefined
git push --force origin main
undefined

2. ALWAYS Use Feature Branches for Writes

2. 写入操作必须使用功能分支

All write operations MUST use a dedicated feature branch:
  • write
    ,
    move
    ,
    copy
    commands require
    --branch <name>
  • Branch name should be descriptive (e.g.,
    update-cmux-docs-20260222
    )
  • NEVER commit directly to
    main
所有写入操作必须使用专用功能分支:
  • write
    move
    copy
    命令需要
    --branch <name>
    参数
  • 分支名称应具备描述性(例如
    update-cmux-docs-20260222
  • 绝不要直接提交到
    main
    分支

3. ALWAYS Create PR for Merge

3. 合并必须创建PR

After writing to a branch, create a PR and let user review:
bash
gh pr create --repo <owner/repo> --head <branch> --base main \
  --title "Update notes" --body "Changes: ..."
NEVER auto-merge without user confirmation.
向分支写入内容后,创建PR并等待用户审核:
bash
gh pr create --repo <owner/repo> --head <branch> --base main \
  --title "Update notes" --body "Changes: ..."
绝不要在未获得用户确认的情况下自动合并。

4. Prefer Local Vault When Available

4. 优先使用本地库

If a local vault exists at
~/Documents/obsidian_vault/
:
  1. Use local git operations instead of GitHub API
  2. Commit changes locally first
  3. Push with
    git push
    (not force push)
  4. This preserves git history and allows easy recovery via
    git reflog
如果
~/Documents/obsidian_vault/
路径下存在本地库:
  1. 使用本地git操作而非GitHub API
  2. 先在本地提交更改
  3. 使用
    git push
    推送(不要强制推送)
  4. 这样可以保留git历史记录,并且可通过
    git reflog
    轻松恢复数据

5. Read Before Write

5. 先读后写

Before updating any file:
  1. read
    the existing file content
  2. Show diff to user if content differs significantly
  3. Only proceed with user confirmation for large changes
更新任何文件前:
  1. 使用
    read
    命令读取现有文件内容
  2. 如果内容差异较大,向用户展示差异
  3. 仅在用户确认后再进行大的更改

6. Single-File Operations Only

6. 仅支持单文件操作

  • Write/move/copy ONE file per commit
  • NEVER batch multiple unrelated files in one branch
  • This makes rollback easier if something goes wrong
  • 每次提交仅对单个文件执行写入/移动/复制操作
  • 绝不要在一个分支中批量处理多个不相关文件
  • 这样在出现问题时更容易回滚

Obsidian Note Authoring Guidelines

Obsidian 笔记编写指南

When creating or editing notes in an Obsidian vault, follow these conventions:
  • If the workspace/repo has an
    AGENTS.md
    , read it and follow it (it overrides these defaults).
在Obsidian库中创建或编辑笔记时,请遵循以下约定:
  • 如果工作区/仓库中存在
    AGENTS.md
    文件,请先阅读并遵循其中的规则(它会覆盖以下默认规则)。

Markdown

Markdown 规范

  • Prefer a short
    ## TL;DR
    near the top for human scanning.
  • Use Obsidian wikilinks (
    [[note-title]]
    ) for internal references instead of raw URLs.
  • Keep headings stable; rename/move only when explicitly asked (links depend on titles/paths).
  • Use YAML frontmatter for metadata (tags, aliases, dates).
  • 优先在顶部附近添加简短的
    ## TL;DR
    部分,方便人工快速浏览。
  • 使用Obsidian维基链接(
    [[note-title]]
    )进行内部引用,而非原始URL。
  • 保持标题稳定;仅在明确要求时才重命名/移动(链接依赖于标题/路径)。
  • 使用YAML前置元数据存储标签、别名、日期等信息。

Mermaid (Obsidian Compatibility)

Mermaid(Obsidian 兼容性)

Obsidian's Mermaid renderer has quirks. Follow these rules to avoid rendering failures:
  • Prefer
    graph TB
    /
    sequenceDiagram
    over newer Mermaid syntaxes.
  • Avoid
    subgraph ID[Label]
    style; use quoted titles:
    subgraph "Title"
    .
  • Avoid
    \n
    in node labels; use
    <br/>
    or keep labels single-line.
  • Avoid parentheses and slashes in node labels; Obsidian chokes on
    (...)
    or
    a/b
    inside
    [...]
    .
  • Keep node IDs ASCII and simple (
    OC_GW
    ,
    CMUX_DB
    ); avoid punctuation in IDs.
  • If a diagram fails to render, simplify first (remove subgraphs/line breaks), then add complexity back.
Obsidian的Mermaid渲染器有一些特性。请遵循以下规则避免渲染失败:
  • 优先使用
    graph TB
    /
    sequenceDiagram
    ,而非较新的Mermaid语法。
  • 避免使用
    subgraph ID[Label]
    格式;使用带引号的标题:
    subgraph "Title"
  • 避免在节点标签中使用
    \n
    ;使用
    <br/>
    或保持标签为单行。
  • 避免在节点标签中使用括号和斜杠;Obsidian在
    [...]
    内遇到
    (...)
    a/b
    时会出现问题。
  • 节点ID使用简单的ASCII字符(例如
    OC_GW
    CMUX_DB
    );避免在ID中使用标点符号。
  • 如果图表渲染失败,先简化(移除子图/换行符),然后再逐步添加复杂内容。

Vault Organization Conventions

库组织约定

Typical Obsidian vault folder structure (emoji prefixes for sorting):
DirectoryPurpose
0️⃣-Inbox/
Uncategorized new notes
1️⃣-Index/
Maps of content (MOCs), overviews
2️⃣-Drafts/
Work-in-progress ideas
3️⃣-Plugins/
Plugin docs and configs
4️⃣-Attachments/
Non-image assets (PDFs, sheets)
5️⃣-Projects/
Project documentation by category
assets/
Images and media
100-Templates/
Reusable note templates
典型的Obsidian库文件夹结构(使用表情符号前缀排序):
目录用途
0️⃣-Inbox/
未分类的新笔记
1️⃣-Index/
内容地图(MOC)、概览文档
2️⃣-Drafts/
正在开发中的想法
3️⃣-Plugins/
插件文档和配置文件
4️⃣-Attachments/
非图片资源(PDF、表格等)
5️⃣-Projects/
按分类整理的项目文档
assets/
图片和媒体文件
100-Templates/
可复用的笔记模板

Project Folder Convention (
5️⃣-Projects/
)

项目文件夹约定(
5️⃣-Projects/

Each project folder MUST have a
_Overview.md
file as its Map of Content (MOC):
5️⃣-Projects/
├── GitHub/
│   ├── cmux/
│   │   ├── _Overview.md          # MOC index (required)
│   │   ├── cmux-tech-stack.md
│   │   └── ...
│   └── openclaw/
│       ├── _Overview.md          # MOC index (required)
│       ├── openclaw-local-status.md
│       └── ...
├── Infrastructure/
│   └── k8s/
│       └── _Overview.md
└── Research/
    └── _Overview.md
_Overview.md
Template Structure
:
  • Start with
    # Project Name (MOC)
    heading
  • Use
    > [!info] Map of Content
    callout with project metadata (repo, stack, updated date)
  • Include Quick Navigation table linking key documents
  • Include Documentation Index with Status column (Current, Reference, Active, etc.)
  • Add architecture diagram (Mermaid) if applicable
  • Include Cross-References section by topic
  • End with Document Status Legend and Last Updated date
When creating a new project folder:
  1. Create the folder under appropriate category (GitHub, Infrastructure, Research)
  2. Create
    _Overview.md
    as the first file
  3. Follow the MOC template structure
  4. Link all related documents from the overview
When creating new notes:
  • Place uncategorized notes in
    Inbox
    for later review.
  • Use links and tags for navigation, not deep folder nesting.
  • Check existing structure with
    list
    before assuming folder names.
每个项目文件夹必须包含一个
_Overview.md
文件作为其内容地图(MOC):
5️⃣-Projects/
├── GitHub/
│   ├── cmux/
│   │   ├── _Overview.md          # 必填的MOC索引
│   │   ├── cmux-tech-stack.md
│   │   └── ...
│   └── openclaw/
│       ├── _Overview.md          # 必填的MOC索引
│       ├── openclaw-local-status.md
│       └── ...
├── Infrastructure/
│   └── k8s/
│       └── _Overview.md
└── Research/
    └── _Overview.md
_Overview.md
模板结构
  • # Project Name (MOC)
    标题开头
  • 使用
    > [!info] Map of Content
    提示框展示项目元数据(仓库、技术栈、更新日期)
  • 包含快速导航表格,链接到关键文档
  • 包含带状态列(当前、参考、活跃等)的文档索引
  • 如有需要,添加架构图(Mermaid格式)
  • 按主题添加交叉引用部分
  • 末尾添加文档状态图例和最后更新日期
创建新项目文件夹时
  1. 在适当的分类(GitHub、Infrastructure、Research)下创建文件夹
  2. 首先创建
    _Overview.md
    文件
  3. 遵循MOC模板结构
  4. 从概览文档链接所有相关文档
创建新笔记时:
  • 将未分类的笔记放在
    Inbox
    中,待后续审核。
  • 使用链接和标签进行导航,而非深层文件夹嵌套。
  • 在假设文件夹名称前,使用
    list
    命令检查现有结构。

Templates

模板使用

  • For GitHub project notes, read and use
    100-Templates/github-project-template.md
    as the starting structure.
  • Read the template:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> read \
      "100-Templates/github-project-template.md"
  • To scaffold a new project folder with
    _Overview.md
    :
    bash
    # Create the _Overview.md as the MOC index
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> copy \
      "100-Templates/github-project-template.md" \
      "5️⃣-Projects/GitHub/<project>/_Overview.md" \
      --branch "add-project-docs" \
      --message "Add project overview MOC"
  • For additional notes in the project folder:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> write \
      "5️⃣-Projects/GitHub/<project>/<note-name>.md" \
      --stdin \
      --branch "add-project-docs" \
      --message "Add project note"
  • 对于GitHub项目笔记,请阅读并使用
    100-Templates/github-project-template.md
    作为起始结构。
  • 读取模板:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> read \
      "100-Templates/github-project-template.md"
  • 使用模板搭建带
    _Overview.md
    的新项目文件夹:
    bash
    # 创建作为MOC索引的_Overview.md
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> copy \
      "100-Templates/github-project-template.md" \
      "5️⃣-Projects/GitHub/<project>/_Overview.md" \
      --branch "add-project-docs" \
      --message "Add project overview MOC"
  • 为项目文件夹添加额外笔记:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> write \
      "5️⃣-Projects/GitHub/<project>/<note-name>.md" \
      --stdin \
      --branch "add-project-docs" \
      --message "Add project note"

Repo Resolution Policy

仓库解析规则

Resolve the repository in this order:
  1. If the user provides
    --repo <owner/repo>
    , use it.
  2. If the user provides
    --repo <key>
    (no
    /
    ), resolve it via
    ~/.config/obsidian-gh-knowledge/config.json
    at
    repos.<key>
    .
  3. If
    --repo
    is omitted, use
    default_repo
    from the same config file.
  4. If none of the above is available, ask the user for the repo or ask them to set local config.
Never guess repo names.
按以下顺序解析仓库:
  1. 如果用户提供
    --repo <owner/repo>
    ,则使用该仓库。
  2. 如果用户提供
    --repo <key>
    (不含
    /
    ),则通过
    ~/.config/obsidian-gh-knowledge/config.json
    文件中的
    repos.<key>
    解析。
  3. 如果未提供
    --repo
    ,则使用同一配置文件中的
    default_repo
  4. 如果以上都不可用,请用户提供仓库信息或指导用户配置本地文件。
绝不要猜测仓库名称。

Requirements

环境要求

  • GitHub CLI installed:
    gh
  • Authenticated:
    gh auth status
  • 已安装GitHub CLI:
    gh
  • 已完成身份验证:
    gh auth status

Commands

命令说明

All operations are performed via the bundled script:
bash
python3 scripts/github_knowledge_skill.py --repo <owner/repo> <command> [args]
If the skill is installed globally, the script is typically located at:
bash
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> <command> [args]
  • list --path <path>
    : List files in a directory.
  • read <file_path>
    : Read file content.
  • search <query>
    : Search code/content.
  • move <src> <dest> --branch <branch_name> --message <commit_msg>
    : Move/rename a file by creating the destination file and deleting the source file on a branch.
  • copy <src> <dest> --branch <branch_name> --message <commit_msg>
    : Copy a file by creating the destination file on a branch.
  • write <file_path> --stdin|--from-file <path> --branch <branch_name> --message <commit_msg>
    : Create or update a file on a branch.
所有操作均通过捆绑的脚本执行:
bash
python3 scripts/github_knowledge_skill.py --repo <owner/repo> <command> [args]
如果技能已全局安装,脚本通常位于:
bash
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo <owner/repo> <command> [args]
  • list --path <path>
    :列出目录中的文件。
  • read <file_path>
    :读取文件内容。
  • search <query>
    :搜索代码/内容。
  • move <src> <dest> --branch <branch_name> --message <commit_msg>
    :通过在分支上创建目标文件并删除源文件来移动/重命名文件。
  • copy <src> <dest> --branch <branch_name> --message <commit_msg>
    :在分支上创建目标文件以完成复制操作。
  • write <file_path> --stdin|--from-file <path> --branch <branch_name> --message <commit_msg>
    :在分支上创建或更新文件。

Repo Selection (Local Config)

仓库选择(本地配置)

To avoid hard-coding a personal repo in prompts, store your vault repo(s) locally and have the agent/tooling read it.
First-time setup: create
~/.config/obsidian-gh-knowledge/config.json
:
json
{
  "default_repo": "<owner>/<vault-repo>",
  "repos": {
    "personal": "<owner>/<vault-repo>",
    "work": "<org>/<work-vault-repo>"
  }
}
Usage (resolve repo at runtime):
bash
REPO="$(python3 -c 'import json,os; p=os.path.expanduser("~/.config/obsidian-gh-knowledge/config.json"); print(json.load(open(p))["default_repo"])')"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" list --path "0️⃣-Inbox"
If the user specifies a repo key (e.g.,
work
), resolve it from
repos.<key>
instead of
default_repo
.
Example (resolve repo key):
bash
REPO="$(python3 -c 'import json,os; p=os.path.expanduser("~/.config/obsidian-gh-knowledge/config.json"); c=json.load(open(p)); print(c["repos"]["work"])')"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "dev plan"
为避免在提示中硬编码个人仓库,请将你的库仓库信息存储在本地,让代理/工具读取。
首次设置:创建
~/.config/obsidian-gh-knowledge/config.json
文件:
json
{
  "default_repo": "<owner>/<vault-repo>",
  "repos": {
    "personal": "<owner>/<vault-repo>",
    "work": "<org>/<work-vault-repo>"
  }
}
使用方法(运行时解析仓库):
bash
REPO="$(python3 -c 'import json,os; p=os.path.expanduser("~/.config/obsidian-gh-knowledge/config.json"); print(json.load(open(p))["default_repo"])')"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" list --path "0️⃣-Inbox"
如果用户指定了仓库密钥(例如
work
),则从
repos.<key>
而非
default_repo
解析。
示例(解析仓库密钥):
bash
REPO="$(python3 -c 'import json,os; p=os.path.expanduser("~/.config/obsidian-gh-knowledge/config.json"); c=json.load(open(p)); print(c["repos"]["work"])')"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "dev plan"

Quick Workflow Example

快速工作流示例

When asked to find and read a note:
  1. List to discover exact paths:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" list --path "1️⃣-Index"
  2. Search if the path is unknown:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "MOC"
  3. Read the target file:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" read "1️⃣-Index/README.md"
当用户要求查找并读取笔记时:
  1. 列出目录以获取精确路径:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" list --path "1️⃣-Index"
  2. 如果路径未知,使用搜索:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "MOC"
  3. 读取目标文件:
    bash
    python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" read "1️⃣-Index/README.md"

Search Query Tips

搜索查询技巧

The
search
command uses GitHub code search. Include qualifiers directly in your query string:
bash
undefined
search
命令使用GitHub代码搜索。可在查询字符串中直接包含限定符:
bash
undefined

Search in specific folder

在特定文件夹中搜索

python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "TODO path:1️⃣-Index/"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "TODO path:1️⃣-Index/"

Search project notes

搜索项目笔记

python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "project plan path:5️⃣-Projects/ extension:md"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "project plan path:5️⃣-Projects/ extension:md"

Find all project overviews

查找所有项目概览文件

python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "filename:_Overview.md"
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "filename:_Overview.md"

Find specific project overview

查找特定项目概览文件

python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "filename:_Overview.md path:5️⃣-Projects/GitHub/cmux"
undefined
python3 ~/.agents/skills/obsidian-gh-knowledge/scripts/github_knowledge_skill.py --repo "$REPO" search "filename:_Overview.md path:5️⃣-Projects/GitHub/cmux"
undefined

Workflow Reference

工作流参考

See
references/obsidian-organizer.md
for a concrete organizing workflow that uses these commands.
请查看
references/obsidian-organizer.md
文件,获取使用这些命令的具体整理工作流。

Notes

注意事项

  • search
    uses GitHub code search; results may be empty for new commits until GitHub indexes them (typically seconds to minutes).
  • Qualifiers like
    path:
    ,
    extension:
    ,
    filename:
    can narrow results - include them directly in the query string.
  • Paths must match the repo exactly (including emoji and normalization). Use
    list
    to discover the exact directory names.
  • Every project folder under
    5️⃣-Projects/
    MUST have a
    _Overview.md
    file as its MOC index.
  • When creating new project documentation, always create
    _Overview.md
    first, then add related notes.
  • search
    命令使用GitHub代码搜索;新提交的内容可能需要几秒到几分钟的时间才能被GitHub索引,因此可能会出现无结果的情况。
  • path:
    extension:
    filename:
    等限定符可缩小搜索范围 - 直接在查询字符串中包含它们即可。
  • 路径必须与仓库中的路径完全匹配(包括表情符号和标准化格式)。使用
    list
    命令获取精确的目录名称。
  • 5️⃣-Projects/
    下的每个项目文件夹必须包含一个
    _Overview.md
    文件作为其MOC索引。
  • 创建新项目文档时,请始终先创建
    _Overview.md
    ,再添加相关笔记。

Recovery Procedures

恢复流程

If files are accidentally deleted or corrupted:
如果文件被意外删除或损坏:

From Local Vault (Preferred)

从本地库恢复(优先推荐)

bash
cd ~/Documents/obsidian_vault
git reflog                          # Find good commit
git reset --hard <commit-sha>       # Restore locally
git push --force origin main        # Sync to remote (only if local is source of truth)
bash
cd ~/Documents/obsidian_vault
git reflog                          # 查找可用的提交记录
git reset --hard <commit-sha>       # 在本地恢复
git push --force origin main        # 同步到远程(仅当本地为可信数据源时使用)

From Remote (if local is lost)

从远程恢复(如果本地库丢失)

bash
undefined
bash
undefined

List commits to find pre-deletion state

列出提交记录以查找删除前的状态

gh api repos/<owner>/<repo>/commits --jq '.[].sha' | head -10
gh api repos/<owner>/<repo>/commits --jq '.[].sha' | head -10

Check file count at each commit

检查每个提交的文件数量

gh api repos/<owner>/<repo>/git/trees/<sha>?recursive=1 --jq '.tree | length'
gh api repos/<owner>/<repo>/git/trees/<sha>?recursive=1 --jq '.tree | length'

Reset remote to good commit (DANGEROUS - confirm with user first)

将远程仓库重置到可用的提交记录(危险操作 - 请先获得用户确认)

gh api -X PATCH repos/<owner>/<repo>/git/refs/heads/main
-F sha=<good-commit-sha> -F force=true
undefined
gh api -X PATCH repos/<owner>/<repo>/git/refs/heads/main
-F sha=<good-commit-sha> -F force=true
undefined

Comparison: GitHub API vs Local Git

GitHub API vs 本地Git 对比

OperationGitHub APILocal Git
RecoveryHard (no reflog)Easy (reflog)
Atomic commitsPer-file onlyMulti-file
SpeedSlower (HTTP)Faster
OfflineNoYes
Audit trailLimitedFull
Recommendation: When
~/Documents/obsidian_vault/
exists, prefer local git operations.
操作GitHub API本地Git
数据恢复困难(无reflog)简单(有reflog)
原子提交仅支持单文件支持多文件
速度较慢(HTTP请求)较快
离线支持不支持支持
审计追踪有限完整
推荐:当
~/Documents/obsidian_vault/
路径存在时,优先使用本地git操作。