问题
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?
回答1:
From git-scm http://git-scm.com/docs/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:
johndoe@server.com:~# 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 show 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
.
回答2:
The command explains itself quite well, it's to figure out which co-worker wrote the specific line or ruined the project so you can blame them :)
回答3:
From GitHub https://help.github.com/articles/using-git-blame-to-trace-changes-in-a-file
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.
回答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, generally these could help.
回答5:
The git blame command annotates line with information from the revision which last modified the line, and... with Git 2.22 (Q2 2019), will do so faster, because of a performance fix around "git blame
", especially in a linear history (which is the norm we should optimize for).
See commit f892014 (02 Apr 2019) by David Kastrup (fedelibre).
(Merged by Junio C Hamano -- gitster -- in commit 4d8c4da, 25 Apr 2019)
blame.c
: don't drop origin blobs as eagerlyWhen a parent blob already has chunks queued up for blaming, dropping the blob at the end of one blame step will cause it to get reloaded right away, doubling the amount of I/O and unpacking when processing a linear history.
Keeping such parent blobs in memory seems like a reasonable optimization that should incur additional memory pressure mostly when processing the merges from old branches.
来源:https://stackoverflow.com/questions/31203001/what-does-git-blame-do