How to git blame who edited the file line?

Using

git blame file 

will show all the information about each line, for example, who adds this line, in which it is fixed, and when, but as far as I know, Git will add a completely new object every time you change the file. So where does Git store such information about each line?

+4
source share
2 answers

As @mvp said, "it is not." To answer your comment: "thread of this process" - it works in much the same way as the git diff s series, starting with the most recent version of the file and working backwards until each line has a designated beginning.

Suppose you have a short file with four lines and it is the most recent (i.e. the version in HEAD ). Suppose further that git diff shows that in the HEAD~1 revision there were only the first three lines, and I added this last (fourth) line. Then the โ€œerrorโ€ for line 4 will be mine: it was not in the previous version, and it was there in the current version, so I had to add it.

This leaves the problem of figuring out who โ€œblamesโ€ these three lines. So now git should distinguish between HEAD~1 and HEAD~2 . If these three lines look exactly the same as in HEAD~2 , which can be, if, for example, the change from HEAD~2 to HEAD~1 was just a deletion of some lines, then we must continue to move forward in history.

At some point, git diff will show that someone has added line 1, line 2 and / or line 3 (in some previous version), possibly when deleting some other lines; or in the worst case, git will reach "root commit": commit without parents. In any case, the one who committed the fixation that caused these lines to appear should be to blame.

+4
source

Where does Git store such information about each line?

Git does NOT store this information anywhere, at least not explicitly. Each time you run git blame file , this information is dynamically computed from objects stored in the Git object repository. If you are interested in knowing exactly how this is done, you can read the blame.c source code for Git .

+1
source

Source: https://habr.com/ru/post/1491048/


All Articles