What does 'git blame' do?
Solution 1
From git-blame:
Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision.
When specified one or more times, -L restricts annotation to the requested lines.
Example:
[email protected]:~# git blame .htaccess
...
^e1fb2d7 (John Doe 2015-07-03 06:30:25 -0300 4) allow from all
^72fgsdl (Arthur King 2015-07-03 06:34:12 -0300 5)
^e1fb2d7 (John Doe 2015-07-03 06:30:25 -0300 6) <IfModule mod_rewrite.c>
^72fgsdl (Arthur King 2015-07-03 06:34:12 -0300 7) RewriteEngine On
...
Please note that git blame
does not show the per-line modifications history in the chronological sense.
It only shows who was the last person to have changed a line in a document up to the last commit in HEAD
.
That is to say that in order to see the full history/log of a document line, you would need to run a git blame path/to/file
for each commit in your git log
.
Solution 2
It's to figure out which co-worker wrote the specific line or ruined the project, so you can blame them :)
Solution 3
The blame command is a Git feature, designed to help you determine who made changes to a file.
Despite its negative-sounding name, git blame is actually pretty innocuous; its primary function is to point out who changed which lines in a file, and why. It can be a useful tool to identify changes in your code.
Basically, git-blame
is used to show what revision and author last modified each line of a file. It's like checking the history of the development of a file.
Solution 4
The git blame
command is used to know who/which commit is responsible for the latest changes made to a file. The author/commit of each line can also been seen.
git blame filename
(commits responsible for changes for all lines in code)
git blame filename -L 0,10
(commits responsible for changes from line "0" to line "10")
There are many other options for blame, but generally these could help.
Solution 5
The git blame
command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.
If there was a bug in code,use it to identify who cased it,then you can blame him. Git blame is get blame(d).
If you need to know history of one line code,use git log -S"code here"
, simpler than git blame.
Himanshu Mishra
Updated on July 08, 2022Comments
-
Himanshu Mishra almost 2 years
I saw a lot of questions about methods of using
git blame
, but I don't really understand them.I see a Blame button on top of files on the GitHub interface. Upon clicking it, it shows some diff with usernames on the left bar. What does that indicate?
Why is
git blame
actually used, apart from GitHub? -
Francisco C. almost 7 yearsThe command actually sounds like you will be blaming someone by running it. At least that is how it sounded to me before I learned what it did in this post.
-
user1431356 over 6 yearsThis seems redundant to me, you can see a diff between commits and ID the user from the commit log. If I'm understanding everything here, it has less persistence than the commit history. Maybe I'm missing something, but it seems like coding standards enforced through public humiliation.
-
Mladen B. about 6 yearsI guess the name of the command was the result of the Linus' specific sense of humor :) It wasn't meant to be used to humiliate anyone :) it was just a funny (or not) pick for a name of a useful command :)
-
azernik about 6 years@user1431356 - the point is that you want the first log line that affects a particular line. Otherwise you'd need to search through the logs for a particular string. (Which is indeed a viable approach - look in the man pages for "git log -S".)
-
DustWolf about 6 years@FranciscoC. you're looking for this: github.com/jayphelps/git-blame-someone-else
-
JackAce almost 6 yearsThe "blame" title is something that has existed for years before git. Just look at svn's implementation. It was not a name given by Linus Torvalds.
-
IanDess over 5 years@FranciscoC. wait what, doesn't it kinda do exactly that i.e. lets you blame someone else?
-
Francisco C. over 5 years@IanDess Perhaps it's just semantics, but
git blame
sounds as if it would have some persisted effect, similar togit commit
, where in fact it just informs you to of what changes were made by who. That and the negative connotation the word "blame" carries, make the command sound like something you should stay away from and leads to questions like this one seeking clarification. -
Rıfat Erdem Sahin over 5 yearsso it is just for the to see the last person?
-
pfnuesel over 5 yearsClearly, it should be called
git praise
. -
Mark over 5 yearsYes, it allows you to see the last person who changed the line.
-
Sinaesthetic about 5 years"I guess the name of the command was the result of the Linus' specific sense of humor :) It wasn't meant to be used to humiliate anyone :)" lol... More like it was Linus's personality and it WAS meant to humiliate someone.
-
Nagarajan Shanmuganathan almost 5 years@Mark So when we annotate on an IDE, it internally makes a git blame command?
-
Mark almost 5 years@NagarajanShanmuganathan yes, if you use git then that is what's happening behind the scenes.
-
mr5 over 4 yearsIn VS for Mac, they labeled the
git blame
asAuthors
. It makes more sense and removes the awkwardness when someone is viewing the "blame" history. -
volvox over 3 yearsGiven Linus found the definition of Git so amusing and hence named the system after it given he considered himself one, Blame may be construed as fitting perfectly. en.wikipedia.org/wiki/Git_(slang) and pcworld.idg.com.au/article/129776/…
-
Kristian Heitkamp about 2 yearsI think it should be named 'view authors'.