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

Git提交摘要与详情存储位置及.git目录完整提交消息文件查询

Where Git Stores Commit Summaries & Details, and How to Access Them as Text Files

Great question—let’s break this down so you understand exactly where Git stores your commit data, and how to get those full commit messages into a text file like you want.

Core Storage: Git’s Object Database

Git saves every commit (including its full message—summary and details) as a compressed object in the .git/objects/ directory. Each commit gets a unique SHA-1 hash: the first two characters of the hash become a subdirectory name, and the remaining characters are the filename of the compressed object. For example:

  • If your commit hash is 7a3f9b2d1e, the object lives at .git/objects/7a/3f9b2d1e...

Heads Up: These Files Are Compressed

Don’t try opening these files directly in a text editor—they’re zlib-compressed, so you’ll only see gibberish. Git provides built-in tools to decompress and view their content.

How to Export Full Commit Messages to a Text File

Git doesn’t store uncompressed plain-text files of old commit messages by default (it’s all about storage efficiency), but you can easily export them manually:

  1. Grab the commit hash you want to view. Run git log to see your commit history—each entry starts with a hash (you only need the first 5-7 characters, not the full string).
  2. Export the full message to a text file using one of these commands:
    • To get the full commit data (message + author/date metadata) in a readable format:
      git cat-file -p <commit-hash> > my-commit.txt
      
    • If you only want the raw commit message (no metadata), use this:
      git log --format=%B -n 1 <commit-hash> > my-commit-message.txt
      
      The %B flag pulls the full raw message, and -n 1 limits output to just that one commit.

Clarifying the Files You Mentioned

To confirm your observations:

  • .git/COMMIT_EDITMSG: This is just a temporary file that holds the most recent commit message you edited (either for an in-progress commit or the last one you made). It never stores historical commit data.
  • Default git log output: It only shows the commit summary by design. To view the full message in the console, use git log --pretty=full or git show <commit-hash> (which also displays the commit’s code changes alongside the message).

Git’s design prioritizes efficiency over easy plain-text access to old commits, but the export commands above let you get the full message into a text file whenever you need it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:24:06