Last Updated: January 3, 2026
Understanding the history of your project is crucial when working with Git.
The git log command serves as your time machine, allowing you to see a detailed history of all your commits. It is not just a list of changes; it provides context, authorship, dates, and much more.
In this chapter we will learn what git log is and how to leverage it effectively to enhance your workflow significantly.
git logAt its core, git log displays the commit history of your repository. When you run this command, Git traverses the commit graph and presents a chronological list of commits.
Each entry contains vital information, including:
To see a straightforward list of commits, simply use:
You will see an output similar to this:
In this example, the commit hash 9a3c6723ab6b9e4e2e9c9a5e4b5f1e321e5b926e uniquely identifies the first commit. This hash is essential when you need to refer to specific commits later.
Each log entry provides a snapshot of the project at the time of the commit. The commit message is particularly important; it often summarizes the changes made. A well-written commit message can save time later when you need to track down when and why changes were made.
While the default output is useful, you can customize git log to display information according to your needs. Here are some common options:
Using the --pretty flag, you can change how the output looks. For example:
This command condenses each commit to a single line, showing only the commit hash and message:
You can also filter the log based on several criteria:
This shows commits made by "John Smith" only.
This retrieves commits from the last two weeks.
You can combine options to tailor the output further. For instance, to see a single line summary of commits from a specific author in the last month:
For more tailored output, git log supports custom format strings using the --pretty=format: option. This allows you to specify exactly what information you want to see.
For example:
In this command:
%h is the abbreviated hash%an is the author name%ar is the time since the commit (e.g., "2 weeks ago")%s is the commit messageThis provides a clean and informative layout. You can combine various placeholders to create your desired output.
Sometimes, seeing a graphical representation of your commit history can be more insightful than a list. You can use the --graph option, which visualizes the branching and merging in your commit history.
The --oneline flag condenses the output to a single line per commit, and --decorate adds branch names and tags to the output. The result will look like this:
This output helps you quickly grasp the structure of your project history, revealing how branches and merges relate to each other.
git log is not just about listing commits; it can show you what changes were made, too.
By appending the -p or --patch option, you can see the diffs for each commit.
This command will display each commit along with the changes introduced by that commit. The output might look like this:
This shows exactly what modifications were made in that specific commit, allowing you to understand the context and impact of the change.
git shortlog is a summary view of your commit history, grouped by author.
Instead of listing every commit line by line like git log, it collapses them into a readable “who did what” view, often used for changelogs or contribution summaries.
You’ll see something like:
If you only want to see the count of commits and not actual commit messages, you can use the flag -s.
Sample Output:
-n (numeric): sort by number of commits (most active first).Now that you understand how to navigate and customize your commit history with git log, you are ready to explore the differences between commits using git diff.
In the next chapter, we will look at how to compare changes between commits and see what has been modified since your last commit.