Keeping track of changes in Git is crucial for understanding your project’s history and troubleshooting issues. The git log
command helps you view past commits, see who made changes, and analyze your project’s evolution.
In this guide, we’ll explore essential git log
commands every developer should know.
View Basic Commit History
To see the commit history in chronological order, simply run:
This shows details like commit hash, author, date, and commit message.
Display a Compact One-Line Log
Need a quick summary of commits? Use:
Example output:
View a Graph of Branches:
Want to visualize your commit history, especially for multiple branches? Try:
This displays a branching structure of your repository, making it easier to see merges and commits.
Filter Commits by Author
Need to see only commits by a specific developer? Use:
git log --author="Alice"
This will show only the commits made by “Alice.”
Search for a Commit Message
Looking for a commit related to a specific feature or bug fix? Use:
Limit the Number of Commits Displayed
To view only the most recent commits, run:
(Replace 5
with any number.)
Conclusion
Understanding git log
commands helps you track changes, debug issues, and collaborate more effectively. Whether you’re looking for a specific commit, author, or just a quick history overview, these commands will keep you in control.