🇯🇵 日本語 | 🇺🇸 English | 🇪🇸 Español | 🇵🇹 Português | 🇹🇭 ไทย | 🇨🇳 中文

Viewing History! Basic Operations to Check Commit History with git log

In the previous articles, you've learned how to record and undo changes using Git. As you continue to work, the next thing you'll probably want to know is, "What changes have I recorded so far?" Accurately grasping your past work is crucial for tracking down the causes of bugs or confirming when a specific feature was implemented.

This article focuses on the `git log` command, which is useful in such situations. This command is for displaying your project's "logbook"—the commit history—in a clear and understandable way. Let's master how to smartly extract the information you need by making full use of its various options!


Basic Usage of `git log`

First, let's try running the most basic `git log` command. In your terminal (or Git Bash), navigate to the folder of the repository whose history you want to see, and enter the following command.

git log

When you run it, your entire commit history will be displayed in order, from newest to oldest. Each commit includes the following information:

If the history is long, you can press the `q` key to exit the log view.


Making It Easier to Read! Useful `git log` Options

The default `git log` output might be a bit overwhelming and hard to read. Fortunately, `git log` comes with many convenient options to customize the display format.

1. Display History Simply in One Line (`--oneline`)

This is perfect for when you want to see each commit summarized in a single line. It displays only the first 7 characters of the commit ID and the first line of the commit message, allowing you to quickly grasp the overall flow.

git log --oneline

2. Display a List of Changed Files (`--stat`)

Use this to display statistical information for each commit, such as which files were changed and how many lines were added or deleted.

git log --stat

3. Display Specific Code Changes (`-p` or `--patch`)

Use this when you want to see the detailed, code-level changes (diff) for each commit. It clearly shows which lines were added (displayed with a `+`) and which were deleted (displayed with a `-`).

git log -p

4. Limit the Number of Commits Displayed (`-n`)

This is convenient when you just want to take a quick look at the most recent history. For example, to display only the latest 3 commits, do the following:

git log -n 3

5. Display Branch Divergence Graphically (`--graph`)

This displays complex histories, such as those where multiple branches have been merged, in a visually easy-to-understand way with connecting lines. It becomes very readable when combined with `--oneline`.

git log --graph --oneline

Options for Finding Specific History

As a project grows, finding a specific change in the history can become difficult. In such cases, options that allow you to filter the history by specific conditions are helpful.

View the History of a Specific File or Directory

This extracts and displays only the history of when and how a specific file (e.g., `index.html`) has been changed.

git log -- [file_name]

View Commits by a Specific Author (`--author`)

This is useful in team development when you want to check what kind of work a specific member has done.

git log --author="username"

Search by Commit Message Content (`--grep`)

This searches for only those commits whose message contains a specific keyword (e.g., "bug fix").

git log --grep="keyword_to_search"

Conclusion: To Master `git log` is to Master Project History

This time, we've introduced various ways to check commit history using the `git log` command. While basic commands like `git log` or `git log --oneline` are sufficient at first, the options introduced here will become powerful weapons as your projects become more complex.

The ability to freely browse past changes is essential for speeding up problem-solving and maintaining code quality. Be sure to try out the various options and find the display method that works best for you.