Horje
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.

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




Reffered: https://www.geeksforgeeks.org


Git

Related
How To List Only Local Branches? How To List Only Local Branches?
GitHub Relative Link In Markdown File GitHub Relative Link In Markdown File
How To Retrieve Single File From A Specific Revision In Git? How To Retrieve Single File From A Specific Revision In Git?
How To Specify A Branch/Tag When Adding a Git Submodule? How To Specify A Branch/Tag When Adding a Git Submodule?
How To Skip Git Commit Hooks? How To Skip Git Commit Hooks?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13