Why Clean Git Commit Messages Matter and How Git Stores Your Code
This article humorously yet informatively explains the importance of tidy Git commit messages, reveals how Git internally stores commits, trees, and blobs, highlights the problems of repository bloat, and offers concrete best‑practice and bad‑practice guidelines for managing large codebases.
Many companies measure developers by the number of commits and lines of code, which often leads to meaningless commit histories that inflate repository size and create chaotic branch structures.
Typical commit messages like "AoneBuild Merge feautre/777_平台赋能牛逼新特性 to master", "Fix老板CR中建议", "fix again", etc., illustrate the problem.
Good commit messages and proper Git hygiene are essential: squash unnecessary fixes, delete unused branches, and refactor large files.
Git Internal Structure
Git stores data as a tree of objects inside the .git directory.
The refs folder holds branch information, including heads (local branches), remotes (remote branches), and tags (immutable version pointers). Each ref points to a commit.
A commit contains metadata and points to a tree object, which represents the snapshot of the file system at that point. A merge commit has two parents.
Each tree entry includes:
mode : file permissions
type : tree for directories, blob for files (code, images, etc.)
revision (oid) : hash of the object content
Because Git stores the full snapshot of each file for every commit, even small changes can cause storage bloat, especially when large binary files are committed. Use Git LFS for big assets.
Git also keeps all historical versions unless a blob becomes unreachable and is later removed by git gc .
To keep repositories healthy, follow these best practices:
Establish a unified commit‑message format (e.g., Feature: add user login).
Squash trivial commits after code review.
Refactor large monolithic classes.
Use Git LFS for large files.
Maintain an up‑to‑date .gitignore.
Keep the main branch log clean and readable.
Delete stale branches promptly.
Continuously update the README with usage instructions.
Avoid bad practices such as creating unnecessary feature/release branches, merging repeatedly without purpose, and blaming Git for lost code.
By treating Git logs like clear documentation, teams can prevent repository bloat, improve collaboration, and maintain fast clone and build times.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
