git - Show File History and Info for Specific File

Retrieve History Information for a File

git log -p shows the commit hash, author, date, and diff for the specified file, and accepts a filename. The -p flag shows the diff between each revision and its parent:

git log -p -- filename.txt

Example Output

commit f1bce3642c0o2e6c5d10beb5e166x54bf9703f3f
Author: Nashu Kanagiri <nkanagiri@google.com>
Date:   Fri Dec 6 20:56:19 2019 +0000

important changes to this file

diff --git a/resources/square.ts b/resources/square.ts
...

View Previous Version of File

If you'd like to view the file as it was at a certain point in time, pass the commit hash to the git show command, along with the filename (I like to pipe the contents into vim via stdin):

git show f1bce3642c0o2e6c5d10beb5e166x54bf9703f3f:resources/square.ts | vim - -n

Tags

 git  version control  git log