How can I view file history in Git?

GitTimelineGit DiffGit LogRevision History

Git Problem Overview


With Subversion I could use TortoiseSVN to view the history/log of a file.

How can I do this with Git?

I am just looking for the history record for a particular file, and then the ability to compare the different versions.

Git Solutions


Solution 1 - Git

Use git log to view the commit history. Each commit has an associated revision specifier that is a hash key (e.g. 14b8d0982044b0c49f7a855e396206ee65c0e787 and b410ad4619d296f9d37f0db3d0ff5b9066838b39). To view the difference between two different commits, use git diff with the first few characters of the revision specifiers of both commits, like so:

# diff between commits 14b8... and b410...
git diff 14b8..b410
# only include diff of specified files
git diff 14b8..b410 path/to/file/a path/to/file/b

If you want to get an overview over all the differences that happened from commit to commit, use git log or git whatchanged with the patch option:

# include patch displays in the commit history
git log -p
git whatchanged -p
# only get history of those commits that touch specified paths
git log path/a path/b
git whatchanged path/c path/d

Solution 2 - Git

It looks like you want git diff and/or git log. Also check out gitk:

gitk path/to/file
git diff path/to/file
git log path/to/file

Solution 3 - Git

I like to use gitk name_of_file

This shows a nice list of the changes that happened to a file at each commit, instead of showing the changes to all the files. Makes it easier to track down something that happened.

Solution 4 - Git

My favorite is git log -p <filename>, which will give you a history of all the commits of the given file as well as the diffs for each commit.

Solution 5 - Git

You could also use tig for a nice, ncurses-based Git repository browser. To view history of a file:

tig path/to/file

Solution 6 - Git

Many Git history browsers, including git log (and 'git log --graph'), gitk (in Tcl/Tk, part of Git), QGit (in Qt), tig (text mode interface to Git, using ncurses), Giggle (in GTK+), TortoiseGit and git-cheetah support path limiting (e.g., gitk path/to/file).

Solution 7 - Git

Of course, if you want something as close to TortoiseSVN as possible, you could just use TortoiseGit.

Solution 8 - Git

git log --all -- path/to/file should work

Solution 9 - Git

You can use git-diff or git-log.

Solution 10 - Git

TortoiseGit also provides a command line tool to do see the history of a file. Using PowerShell:

C:\Program` Files\TortoiseGit\bin\TortoiseGitProc.exe /command:log /path:"c:\path\to\your\file.txt"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmrblahView Question on Stackoverflow
Solution 1 - GitChristianView Answer on Stackoverflow
Solution 2 - GitbaudtackView Answer on Stackoverflow
Solution 3 - GitGustavo LitovskyView Answer on Stackoverflow
Solution 4 - GitchopperView Answer on Stackoverflow
Solution 5 - Gituser217433View Answer on Stackoverflow
Solution 6 - GitJakub NarębskiView Answer on Stackoverflow
Solution 7 - GitJörg W MittagView Answer on Stackoverflow
Solution 8 - GitEdson MedinaView Answer on Stackoverflow
Solution 9 - GitvladikoffView Answer on Stackoverflow
Solution 10 - GitbriancView Answer on Stackoverflow