tags:

views:

16668

answers:

7

How can I view the change history of an individual file, complete 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 changes ?

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

A: 

git show

DGM
git show does not by itself explain what the question is after
lurscher
and yet gitk filename was the accepted answer? At least mine as a link to the actual documentation. It completely answers "how do I get at the content of each of the changes"
DGM
A: 

If you're using the git GUI (on Windows) under the Repository menu you can use "Visualize master's History. Highlight a commit in the top pane and a file in the lower right and you'll see the diff for that commit in the lower left.

cori
+34  A: 

You can use

git log -p filename

to let git generate the patches for each log entry, see

git help log

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

git show HEAD

or any other revision by identifier. Or use gitk to browse the changes visually.

VolkA
Thanks! I've been looking for this simple solution for a while now. I love git, but the documentation seems to have the same basic standards as Unix man pages. That is to say, if you know what you're looking for you usually can't find the syntax unless you know more about the underlying code.
ShawnMilo
+11  A: 

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

farktronix
+21  A: 

I'd use:

 gitk filename.
ClaudioA
But I rather even have a tool that combined the above with 'git blame' allowing me to browse the source of a file as it changes in time...
Egon Willighagen
+1  A: 

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

git blame filename

yllohy
A: 

Or:

gitx -- <path/to/filename>

if you're using gitx

George Anderson