Useful Git Commands: Blame

Blame! by PrinzKoks
How many times, looking a piece of shared code, have you thought "who the hell has written this?!?!" With other VCS all you can do is to scroll the list of changes made to that particular file and look at what is changed.

But Git provides you the blame command that eventually answers your question in a fast and easy way. And, most of the times, you will not like the answer.

You can see a whole file (or just some rows, with the flag -L) annotated with the author and the hash of the commit where each line has been added or changed. And you can also ignore changes in whitespaces with -w.

Sometimes it may be useful to detect if the same lines have been moved inside the file: the flag -M cover this requirement. But what if the lines have been moved from a file to another?

This is the purpose of the flag -C. If the move has been done in the same commit (typically during a refactoring session) the output shows also the file name where those rows originally were.

Check out the man page for all the other options.

Post a Comment