You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code中快速查看单个及Git提交历史的tree hash?

在VS Code中查看Git提交的Tree Hash(单个/全部)

1. 查看单个提交的Tree Hash

用GitLens插件(最便捷)

  • 先安装GitLens插件,打开左侧源代码管理面板(快捷键Ctrl+Shift+G),切换到「GitLens: Commits」视图
  • 找到目标提交,点击展开详情面板。如果默认没显示Tree Hash,按以下步骤配置:
    • 打开VS Code设置(Ctrl+,),搜索「GitLens: Commit Format」
    • 在自定义格式里加上%T(Tree Hash的占位符),比如改成:%h %an %ar • %s • Tree: %T
    • 保存设置后,所有提交条目后会直接显示对应的Tree Hash,点击提交也能在详情里看到完整哈希值

用命令面板快速调用Git命令

  • 打开命令面板(Ctrl+Shift+P),输入「Git: Show Commit Details」选中目标提交,或者直接输入git log -1 --pretty="%T",接着输入目标提交的短哈希,回车后结果会在输出面板显示

2. 查看所有提交的Tree Hash

用GitLens批量显示

  • 还是用GitLens,在设置里搜索「GitLens: Commit List Format」,同样添加%T字段,提交列表里每一条都会附带Tree Hash,直接滚动查看即可
  • 如果需要导出完整列表,直接在VS Code内置终端执行git log --pretty="%H %T %s",格式为「提交哈希 + Tree Hash + 提交信息」,一目了然

自定义VS Code任务批量导出

  • 在项目的.vscode/tasks.json中添加以下任务:
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Show All Tree Hashes",
      "type": "shell",
      "command": "git log --pretty=\"%H %T %s\"",
      "problemMatcher": []
    }
  ]
}
  • 打开命令面板(Ctrl+Shift+P),选「Tasks: Run Task」再点击「Show All Tree Hashes」,结果会直接在终端面板输出

内容的提问来源于stack exchange,提问作者a06e

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 09:12:37