How To List All Commits That Changed A Specific File In Git?
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.
Table of Content
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

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
