How to list all commits that changed a specific file?

 

You can list all commits that changed a specific file in a Git repository using the git log command with the --follow option followed by the file path. Here's how you can do it with an example:

Suppose you want to list all commits that changed a file named "example.txt."

bash
git log --follow example.txt

This command will display a list of commits that have affected the "example.txt" file, including the commit hash, author, date, and commit message for each relevant commit.

If you want a more compact view of the commit information, you can use the --oneline option:

bash
git log --follow --oneline example.txt

This will provide a condensed list of commits, showing only the commit hash and the commit message for each commit that modified "example.txt."

Keep in mind that the --follow option is necessary when tracking file renames or moves. If you're only interested in commits that modified a file without considering its history through renames, you can omit the --follow option:

bash
git log example.txt

This will list all commits that modified "example.txt" without considering its history through renames.

Remember to replace "example.txt" with the actual file path you want to investigate in your Git repository.

Comments