Git Log
What
The git log command displays the chronological history of all commits saved to a repository. Each entry in the log lists the commit author, timestamp, commit message, and a unique identifier known as a commit hash.
How
You can view your repository’s commit history using the simple git log command:
# View the interactive commit log
git log
When the commit history is longer than your terminal screen, Git opens an interactive viewer (a pager) where you can navigate using your arrow keys or the spacebar, and exit by pressing q.
To bypass the pager or limit the number of commits shown, you can use additional flags:
# View only the last 3 commits without opening the interactive pager
git --no-pager log -n 3
# View a highly condensed, one-line summary of history
git log --oneline
Why
A Commit Hash (e.g., 5ba786fcc93e8092831c01e71444b9baa2228a4f) is a unique SHA-1 hash generated by Git based on the exact content of the files, parent commit, author, and timestamp. For convenience, you can refer to any commit by using its full hash or just the first 7 characters (e.g., 5ba786f). Git log allows you to navigate this web of hashes to understand the lineage of your project, debug regressions, and audits changes.
Summary
Use git log to inspect your repository’s chronological history and find unique commit hashes for auditing and recovery.