git log - View the change history of a file using Git versioning

ID : 136

viewed : 120

Tags : gitgit-loggit

Top 5 Answer for git log - View the change history of a file using Git versioning

vote vote


For a graphical view I'd use gitk:

gitk [filename] 

Or to follow filename past renames:

gitk --follow [filename] 
vote vote


You can use

git log -p filename 

to let Git generate the patches for each log entry.


git help log 

for more options - it can actually do a lot of nice things :) To get just the diff for a specific commit you can

git show HEAD 

or any other revision by identifier. Or use


to browse the changes visually.

vote vote


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.

vote vote


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

Quick Install:

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

Use it to view history on a single file: tig [filename]

Or browse the detailed repository history: tig

It is similar to gitk, but text-based. It supports colors in the terminal!

vote vote


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).

Top 3 video Explaining git log - View the change history of a file using Git versioning