Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Recorder for Obsidian

一个全局版 Git 提交记录器:每次 git commit 成功后,自动把提交记录同步到 Obsidian Vault。

产物

.
├── config.example.json
├── git-recorder.sh
├── install.sh
├── post-commit
├── post-merge
└── post-rewrite

推荐 Obsidian 目录结构

安装后会在你的 Vault 中生成:

Git Records/
├── README.md
├── Daily/
│   └── 2026/
│       └── 06/
│           └── 2026-06-29.md
└── Repos/
    └── repo-name/
        ├── README.md
        └── Commits/
            └── 2026/
                └── 06/
                    └── 2026-06-29/
                        └── abc1234.md

设计思路:

  • Daily/:按天汇总所有仓库提交,适合日报、周报、复盘。
  • Repos/:按仓库沉淀提交详情,适合回溯项目演进。
  • 每个 commit 一个独立 Markdown,方便 Obsidian 双链、搜索和标签管理。

安装

chmod +x install.sh
./install.sh --vault "/path/to/your/ObsidianVault"

安装脚本会:

  1. 复制 git-recorder.sh~/.config/git-recorder/git-recorder.sh
  2. 复制 hooks 到 ~/.config/git/hooks/
  3. 生成 ~/.config/git-recorder/config.json
  4. 设置全局 Git hooks:
git config --global core.hooksPath ~/.config/git/hooks

配置

配置文件位置:

~/.config/git-recorder/config.json

示例:

{
  "obsidianVault": "/Users/YOUR_NAME/Documents/Obsidian",
  "rootDir": "Git Records",
  "includeDiff": true,
  "maxDiffLines": 300,
  "repoNameStrategy": "directory",
  "ignoreRepos": [],
  "ignorePaths": []
}

字段说明:

字段 说明
obsidianVault Obsidian Vault 根目录
rootDir Git 记录根目录,默认 Git Records
includeDiff 是否记录 diff 摘要
maxDiffLines diff 最多记录行数
repoNameStrategy directory 使用目录名;remote 使用远程仓库名
ignoreRepos 忽略仓库名或仓库绝对路径
ignorePaths 忽略某些路径下的仓库

触发方式

post-commit

每次 git commit 成功后触发,写入 commit Markdown,并更新 Daily / Repo 索引。

post-rewrite

用于 git commit --amendgit rebase 等重写场景。当前 MVP 只写日志,不生成详细重写记录。

post-merge

用于 git merge / git pull 后触发。当前 MVP 只写日志,不生成详细 merge 记录。

本地仓库 hook 兼容

全局 hook 会在执行记录器后,尝试执行当前仓库的本地扩展 hook:

.git/hooks/post-commit.local
.git/hooks/post-rewrite.local
.git/hooks/post-merge.local

如果某个项目需要自己的 hook 逻辑,建议放到这些 .local 文件里,避免和全局 core.hooksPath 冲突。

手动测试

进入任意 Git 仓库后执行:

~/.config/git-recorder/git-recorder.sh post-commit

如果配置正确,会在 Obsidian Vault 的 Git Records/ 下生成记录。

查看日志:

tail -f ~/.config/git-recorder/recorder.log

卸载

取消全局 hooks:

git config --global --unset core.hooksPath

删除记录器文件:

rm -rf ~/.config/git-recorder

如果 hooks 目录只用于这个工具,也可以删除:

rm -rf ~/.config/git/hooks

注意:删除前请确认 ~/.config/git/hooks 没有其他你仍然需要的 hook。

About

git-obsidian-hook

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages