The `git log --name-status` command is used to display the commit history along with the status of files that were modified, added, or deleted in each commit.
git log --name-status
What is `git log`?
The `git log` command is a fundamental tool in Git that allows users to view the history of commits in a repository. It serves as a timeline of changes made over the course of the project’s lifecycle. The default output includes the commit hash, author, date, and commit message, providing a textual representation of the changes. The basic syntax for using the command is:
git log [options] [<revision>...]
This command can be tailored with various options to focus on specific aspects of the commit history, such as filtering by date, author, or a particular file.

Understanding the `name-status` Option
The `name-status` option is an extension to the `git log` command that presents a more nuanced view of changes. Instead of just seeing the commit messages, it shows a list of files that were changed, along with their status in the context of the commit. This option brings clarity to the modifications—helping you understand what was added, modified, or deleted without having to dig deeper into individual commits.
The key advantage of using `git log --name-status` is that it provides immediate insight into the scope of changes in each commit. This contrasts sharply with the default output, where you might need to take additional steps to determine what files were impacted by changes.

How to Use `git log --name-status`
To use the `name-status` option, simply run the following command in your terminal:
git log --name-status
Upon executing this command, you will see an output similar to the following:
M file1.txt
A file2.txt
D file3.txt
In this output format, the first column indicates the status code (A, M, D) while the second column presents the respective filenames. Here's an overview of what each status code signifies:
- A: Added — This indicates that a new file has been added to the repository.
- M: Modified — This shows that an existing file has been edited.
- D: Deleted — This suggests that a file has been removed from the repository.
Example: Basic Usage
Let's take a practical example to illustrate the command:
git log --name-status
Suppose you are working on a project, and after running this command, you see the output:
M src/app.js
A src/style.css
D src/old-file.js
Here, the `src/app.js` was modified (M), `src/style.css` was newly added (A), and `src/old-file.js` was deleted (D). Each entry corresponds to the changes made in separate commits, allowing you to understand the evolution of your codebase easily.

Customizing `git log --name-status`
To get the most out of `git log --name-status`, you can customize the output by using several options.
Limit the Number of Commits
Limiting the output to a specific number of commits can make it easier to digest recent changes. For instance, to retrieve the last five commits, you can use:
git log -n 5 --name-status
Displaying Specific Branches or Tags
You can also filter changes by specifying branches or tags. For example, to view the changes on the main branch, run:
git log main --name-status
Example: Customizing Output
Another helpful command is:
git log --since="2 weeks ago" --name-status
This command filters the logs to show changes made in the last two weeks. By customizing the `git log` command, you gain valuable insights into recent project developments tailored to your specific interests.

Filtering Commits
The ability to filter commits is especially crucial for larger projects. The following examples illustrate how to refine your view of the commit history by certain criteria.
Filtering by Author
To find changes made by a specific contributor, you can filter by author using the command:
git log --author="John Doe" --name-status
This will display only the commits attributed to "John Doe," along with their respective file status.
Filtering by Date
You can also filter commits by date to see changes made after a specific point:
git log --after="2023-01-01" --name-status
This command helps track the development progress after a significant date, making it easier to manage ongoing projects.
Example: Filtering Commits
After executing the filtering commands, you might see outputs that look like:
M src/app.js
A docs/new-feature.md
These examples show filtered results based on your criteria, giving you the flexibility to review commits of interest quickly.

Interpreting the `name-status` Output
Understanding the context of file changes is crucial. Each status code provides a quick visual representation of the commit's impact on the codebase. This perception allows developers to associate file modifications with ongoing tasks or issues they might be addressing.
For instance, if you see numerous files marked as "modified," it may indicate an ongoing development cycle that demands review, or if you observe many "added" statuses, it could suggest new features or functionalities being integrated into the project.

Practical Scenarios
The `git log --name-status` command finds real-world applications across various development scenarios:
- Code Reviews: It provides an overview of changes for reviewers, capturing a snapshot of modifications at a glance before diving deeper into the specifics.
- Regression Tracking: You can identify when a bug was introduced, cross-referencing file modifications with reported issues to pinpoint potential causes.
- Release Preparation: Examining what has changed before a release version helps ensure no critical updates are overlooked.
These scenarios illustrate how crucial the `name-status` option is for maintaining efficient project management and collaboration among team members.

Common Pitfalls and Troubleshooting
While using `git log --name-status`, be mindful of several common mistakes:
- Forgetting to Specify the Repository: Ensure you’re in the right Git repository when executing commands to avoid confusion about output.
- Misunderstanding the Status Codes: Familiarize yourself with the meaning behind the status codes to accurately interpret file changes.
If you experience issues, consult the Git documentation or leverage community forums for insights and solutions.

Summary
In summary, mastering `git log name-status` is essential for any Git user seeking to enhance their understanding of version control. The command streamlines the analysis of changes, making it easier to keep track of project developments.
By applying the techniques discussed—customizing with flags, filtering commits, and interpreting outputs effectively—you can efficiently navigate through your repository’s history. Engage with the command frequently to build competence in your Git workflow.

Additional Resources
For those looking to delve deeper into Git, the official Git documentation is an excellent resource for comprehensive information. Furthermore, consider exploring tutorials or books dedicated to Git to broaden your knowledge. Our company also offers courses and resources aspirational to expedite your Git learning journey.

Call to Action
We encourage you to share your experiences with `git log --name-status` in the comments below. If you found this article helpful, consider subscribing for more Git tips and tutorials. Follow us on social media or join our mailing list to stay updated on new posts or courses designed to sharpen your Git skills.