Open In App

How To List All Commits That Changed A Specific File In Git?

Last Updated : 25 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Git, a widely used version control system, allows developers to track changes in their codebase efficiently. One common need when working with Git is to list all commits that have modified a specific file. This can be particularly useful for tracking changes, understanding the history of a file, or identifying when a bug was introduced.

Approach 1: Using git log

git log is a command in Git that displays commit logs. It can be filtered to only show commits that have modified a specific file.

Syntax:

git log -- <file_path>

Example: In this example, we use git log to list all commits that have modified the README.md file.

git log -- README.md
Screenshot-2024-06-05-192340
How to list all commits that changed a specific file in Git

Approach 2: Using git whatchanged

git whatchanged is a historical command in Git that lists commits and the changes they introduced. It can be filtered to show commits that have modified a specific file.

Syntax:

git whatchanged -- <file_path>

Example: In this example, we use git whatchanged to list all commits that have modified the README.md file.

git whatchanged -- README.md
Screenshot-2024-06-05-193058
How to list all commits that changed a specific file in Git

Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg