View the change history of a file using Git versioning


How can I view the change history of an individual file in Git, complete details with what has changed?

I have got as far as:

git log -- [filename]

which shows me the commit history of the file, but how do I get at the content of each of the file changes?

I'm trying to make the transition from MS SourceSafe and that used to be a simple right-clickshow history.

4/28/2017 10:02:25 AM

Accepted Answer

For this I'd use:

gitk [filename]

or to follow filename past renames

gitk --follow [filename]
9/21/2016 8:17:58 AM

git log --follow -p -- path-to-file

This will show the entire history of the file (including history beyond renames and with diffs for each change).

In other words, if the file named bar was once named foo, then git log -p bar (without the --follow option) will only show the file's history up to the point where it was renamed -- it won't show the file's history when it was known as foo. Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo. The -p option ensures that diffs are included for each change.


If you prefer to stay text-based, you may want to use tig.

Quick Install:

  • apt-get: # apt-get install tig
  • Homebrew (OS X): $ brew install tig

Use it to view history on a single file: tig [filename]
Or browse detailed repo history: tig

Similar to gitk but text based. Supports colors in terminal!


git whatchanged -p filename is also equivalent to git log -p filename in this case.

You can also see when a specific line of code inside a file was changed with git blame filename. This will print out a short commit id, the author, timestamp, and complete line of code for every line in the file. This is very useful after you've found a bug and you want to know when it was introduced (or who's fault it was).


SourceTree users

If you use SourceTree to visualize your repository (it's free and quite good) you can right click a file and select Log Selected

enter image description here

The display (below) is much friendlier than gitk and most the other options listed. Unfortunately (at this time) there is no easy way to launch this view from the command line — SourceTree's CLI currently just opens repos.

enter image description here


To show what revision and author last modified each line of a file:

git blame filename

or if you want to use the powerful blame GUI:

git gui blame filename

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]