Command Git Log --name-status: A Powerful Tool for Git Version Control
Git is an essential tool for developers and teams working on collaborative projects. It allows for efficient version control, enabling developers to track changes, collaborate seamlessly, and manage their codebase effectively. One of the most powerful commands in Git is git log, and when combined with the --name-status option, it becomes an incredibly useful tool for tracking the files that have been changed in a commit.
What Does the "git log --name-status" Command Do?
To understand the command, let’s break it down. The git log command is used to show the commit history in a Git repository. By default, it shows a list of commits with their respective commit hash, author, date, and commit message. However, sometimes you need more detailed information about the changes made in each commit. This is where the --name-status option comes in.
The --name-status flag provides a summary of the changes made in each commit, showing the names of the modified files along with their status. This status could be one of the following:
- A – Added
- M – Modified
- D – Deleted
When you run git log --name-status, Git will display a list of commits along with the files changed in each commit, and the status of each file. This command is especially useful when you want to see exactly which files were affected in each commit without diving into the full details of the commit itself.
Why Use the "git log --name-status" Command?
The git log --name-status command offers several benefits for Git users:
- Quick Overview of Changes: It gives you a quick overview of what files were added, modified, or deleted without having to inspect each commit in detail.
- Streamlined Code Review: If you’re reviewing a pull request or commit history, the
--name-statusoption can help you focus on the file-level changes instead of wading through lengthy commit messages. - Efficient Collaboration: When working in a team, you can quickly track what files other team members have modified, added, or deleted.
- Better Debugging: When investigating bugs or issues, you can track which files have been changed recently to pinpoint potential areas of concern.
Basic Syntax and Usage of "git log --name-status"
The basic syntax for the git log --name-status command is straightforward:
git log --name-status
Running this command will show you the commit history, including the files modified in each commit and their status (added, modified, or deleted). Here’s a sample output:
commit 1234abcd5678efgh
Author: John Doe
Date: Tue Mar 2 14:15:00 2025 +0000
Fixed the bug in the login form
A src/login.js
M src/styles.css
D src/oldFeature.js
commit 9876zyxw4321dcba
Author: Jane Smith
Date: Mon Mar 1 10:30:45 2025 +0000
Added user authentication feature
A src/auth.js
M src/login.js
In this output:
- The first commit (1234abcd5678efgh) shows that
login.jswas added,styles.csswas modified, andoldFeature.jswas deleted. - The second commit (9876zyxw4321dcba) shows that
auth.jswas added, andlogin.jswas modified.
This is a simple yet powerful way to quickly identify what files were changed and how they were affected in each commit.
Advanced Usage of "git log --name-status"
While the basic git log --name-status command is incredibly useful, there are also several advanced options that you can combine with it to further tailor the output to your needs. Some of these options include:
1. Limiting the Number of Commits
Sometimes you may not want to see the entire commit history. You can limit the number of commits displayed by adding the -n option followed by the number of commits you want to display. For example, to show the last 5 commits:
git log --name-status -n 5
This will display the last 5 commits, along with the files that were added, modified, or deleted in each commit.
2. Filtering by Commit Range
If you're interested in the changes made between two specific commits, you can specify a commit range. For example, to see the changes between commit abc123 and def456:
git log abc123..def456 --name-status
This will display the commits between the two specified commits, showing the changes made to the files in that range.
3. Showing Changes by Author
If you want to filter the commits by a specific author, you can use the --author flag. For example, to see the commits made by "John Doe":
git log --author="John Doe" --name-status
This will display all the commits made by John Doe, along with the file changes in each commit.
4. Formatting the Output
If you want to customize the output of git log --name-status, you can use the --pretty option. For example, to display a more compact version of the log with just the commit hash and file status:
git log --name-status --pretty=format:"%h %s"
This will show a concise log with the commit hash (%h) and the commit message (%s) along with the file changes. You can adjust the format to suit your needs by using various placeholders in the --pretty option.
Real-World Examples of "git log --name-status"
Let’s take a look at some real-world scenarios where git log --name-status can come in handy:
1. Code Review and Collaboration
If you're reviewing a colleague's pull request or commit history, git log --name-status is a great way to quickly see what files were changed. Instead of manually opening each commit, you can easily identify the files that were affected, making your review process much faster and more efficient.
2. Debugging and Bug Fixes
When investigating a bug, it's often helpful to see which files were modified recently. Using git log --name-status, you can quickly trace the changes and see if the bug was introduced in a specific commit. This helps you identify the root cause of the problem faster.
3. Release Notes Generation
When preparing release notes, it’s important to know what changes were made in each version. git log --name-status can help you generate a list of modified files, making it easier to compile the release notes.
Conclusion
In conclusion, the git log --name-status command is a simple yet powerful tool that can significantly improve your workflow. By giving you a quick overview of file changes in each commit, it enables faster code reviews, debugging, and collaboration. Whether you’re a solo developer or part of a team, mastering this command will help you stay organized and efficient in your Git usage.

Komentarze (0) - Nikt jeszcze nie komentował - bądź pierwszy!