View the change history of a file using Git versioning

For a graphical view, use gitk:

gitk [filename]

To follow the file across file renames:

gitk --follow [filename]

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.


This lets Git generate the patches for each log entry:

git log -p -- filename

See git help log for more options — it can actually do a lot of nice things. :)


To get just the diff for a specific commit, use

git show HEAD

or specify any other revision by identifier.


To browse the changes visually:

gitk

tig is a terminal-based viewer with color support similar to the GUI-based gitk.

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 via: tig

Tags:

Git

Git Log