Is there a way to list all commits that changed a specific file?

 

Yes, you can use the git log command with the --follow option to list all commits that have changed a specific file, even if the file has been renamed or moved over time. Here's how to do it with an example:

bash
git log --follow <file_path>
  • <file_path> is the path to the specific file you want to track.

For example, let's say you want to list all commits that have changed a file named "example.txt." You would use the following command:

bash
git log --follow example.txt

Git will display a list of commits that affected the specified file, including the commit hash, author, date, and commit message.

Here's an example of what the output might look like:

sql
commit 1234567890123456789012345678901234567890 Author: John Doe <johndoe@example.com> Date: Mon Sep 5 10:00:00 2023 -0400 Updated example.txt commit abcdefghijklmnopqrstuvwxyz1234567890 Author: Jane Smith <janesmith@example.com> Date: Fri Sep 2 15:30:00 2023 -0400 Renamed and modified example.txt commit 9876543210987654321098765432109876543210 Author: Alice Johnson <alice@example.com> Date: Wed Aug 30 09:45:00 2023 -0400 Added example.txt

This output lists the commits in reverse chronological order (most recent first) that have affected the "example.txt" file. You can use this information to track changes to a specific file in your Git repository.

Comments