This content originally appeared on DEV Community and was authored by Cristian Sifuentes
Advanced Commands for Exploring Git Internals
Become a Git power user by mastering its low-level inspection and history tools.
While Git’s porcelain commands help manage day-to-day workflows, plumbing commands reveal its internal architecture. This article explores commands like git ls-tree, git rev-parse, git fsck, and advanced git log formats to help you debug, visualize, and verify with confidence.
Inspecting the Git Tree
git ls-tree HEAD
Lists files and directories tracked in the current commit:
git ls-tree HEAD
Output:
100644 blob a4c2e3e file1.txt
100644 blob b6f9d5f file2.txt
040000 tree 3f5e2a7 src
-
100644: File mode (permissions). -
blob/tree: Object type. -
a4c2e3e: Object SHA-1. -
file1.txt: File name.
Retrieve the Latest Commit Hash
git rev-parse HEAD
git rev-parse HEAD
Output:
9b2e3d7a8f00c6e4f88d70a9c2e7fcbf97e6c9c5
This hash is essential for scripting, CI/CD integration, and debugging.
Verifying Repository Integrity
git fsck --full
Performs a deep scan of your repository:
git fsck --full
Output:
Checking object directories: 100%
Checking objects: 100%
If corruption exists:
error: missing blob 8f00c6e4
fatal: object 8f00c6e4 missing
Working with Tags
- Create:
git tag -a v1.0 -m "Version 1.0 release" - List:
git tag - Checkout:
git checkout v1.0 - Delete:
git tag -d v1.0 - Push:
git push --tags
Viewing and Customizing Commit History
git log (Basic)
git log
Shows:
- Commit SHA
- Author
- Date
- Commit message
Patch-Level View
git log -p -2
Outputs the last 2 commits and their file diffs.
File-Level Stats
git log --stat
Outputs:
hello.txt | 3 +--
hello2.txt | 2 ++
2 files changed, 3 insertions(+), 2 deletions(-)
Custom Commit Formats
Single-Line Format
git log --pretty=oneline
Custom Format
git log --pretty=format:"%h - %an, %ar : %s"
Output:
9b2e3d7 - John Doe, 3 days ago : Fixed login bug
Graph View
git log --pretty=format:"%h %s" --graph
Output:
* 9b2e3d7 Fixed login bug
* 4a7e8d9 Refactored authentication
Filtering Git History
Filter by Date
git log --since=2.weeks
git log --since="2024-02-20"
Filter by Change
git log -S "validate_login"
Filter by File Path
git log -- app/models/user.py
Advanced Filters (Author, Time, Scope)
git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" --before="2008-11-01" --no-merges -- t/
Exclude Merge Commits
git log --no-merges
Summary of Advanced Git Internals Commands
| Command | Description |
|---|---|
git ls-tree HEAD |
Lists files and directories in the latest commit. |
git rev-parse HEAD |
Retrieves the current commit hash. |
git fsck --full |
Performs integrity check on the repository. |
git log |
Shows commit history. |
git log -p -2 |
Shows code changes for last 2 commits. |
git log --stat |
Displays file-level statistics. |
git log --pretty=oneline |
Compact one-line view per commit. |
git log --pretty=format: |
Custom commit formatting. |
git log --graph |
Visual graph of commit history. |
git log --since |
Filter commits by date. |
git log -S |
Search by content diff. |
git log -- path/file |
Filter history by file. |
git log --author --since --no-merges |
Filter by metadata. |
Mastering these commands turns Git into a powerful database for code history and architecture. Keep exploring, and unlock Git's full potential!
Follow for more deep dives on Git internals and engineering tools!
This content originally appeared on DEV Community and was authored by Cristian Sifuentes
Cristian Sifuentes | Sciencx (2025-05-08T21:59:07+00:00) Advanced Commands for Exploring Git Internals. Retrieved from https://www.scien.cx/2025/05/08/advanced-commands-for-exploring-git-internals/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
