Git – Particular File Change History

Let say you have a file that is tracked by Git and has a commit history.

Some day you will want to look back to see what has happened with this file.

The most basic and powerful tool to do this is the git log command.

Using the different options, it can show the commit history of a file, history of diffs and up to the history of renames.

Cool Tip: Did something wrong? Want to undo everything? You can easily revert all changes back to the last commit! Read more →

Show The Change History Of A File

Use one of the below commands to get the change history of an individual file using Git.

File history of COMMITS

We know that git log command shows the commit history of the whole project.

But it is not easy to find the commit history of a particular file between the all commits.

To show only commits of an individual file, run this command:

$ git log -- <file>

File history of COMMITS with DIFFS

The above command prints only general information about commits – hash, author, date and comment.

Not much, isn’t it?

In most cases, i think, the more interesting information is what exactly has changed after each commit.

Run the below command to show commits of the particular file with diffs for each change:

$ git log -p -- <file>

File history of COMMITS with DIFFS including RENAMES

Moreover, you even can find out how the file was previously named if it was renamed.

Cool Tip: Have forgotten the meaning of some term in Git? Not a problem! Simply read and bookmark this article! This article →

Show the entire history of a file (including history beyond renames):

$ git log --follow -p -- <file>