How do you show the commit log for a specific file?
Posted by NickCrt
Last Updated: June 05, 2024
To show the commit log for a specific file in Git, you can use the git log command along with the path to the file. Here's the syntax:
git log -- <file_path>
Replace <file_path> with the actual path to the file you want to view the commit history for. For example, if you have a file named example.txt, you would run:
git log -- example.txt
This command will display the commit history for the specified file, showing all commits that have affected it.
Additional Options
You can also use additional flags with git log to customize the output: - -p: Shows the diff introduced in each commit. - --oneline: Displays each commit on a single line, which can make it easier to read. - -n <number>: Limits the number of commits shown. For example, if you want to see a concise log with diffs for the last 5 commits for example.txt, you could run:
git log -p -n 5 -- example.txt
This will give you a straightforward view of the changes made to that specific file along with the relevant code differences in each commit.