Is it possible somehow for GIT to find which commit introduced a specific line of code in a specific file? This is assuming that there have been many commits since that line was added. Or is this something that must be done in a script while looking at the git blame of all the commits for the file in which the line is present?
To clarify
Original file->Line Added to file and committed -> Many other commits adding other lines and changing the code
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.
On GitHub.com, navigate to the main page of the repository. Click to open the file whose line history you want to view. In the upper-right corner of the file view, click Blame to open the blame view.
You can also quit the git blame window using the q key on your keyboard.
The Raw, Blame, and History buttons appear when viewing a single file of a repository. For example, let's visit the README.md file by clicking on it: The Raw button, like the name suggests, opens the file in a raw form, meaning that any HTML formatting disappears.
You can use git blame -l filename
to get the SHA1 hash from when the line was changed.
You also can use --reverse:
--reverse
Walk history forward instead of backward. Instead of showing the revision in which a line appeared, this shows the last revision in which a line has existed. This requires a range of revision like START..END where the path to blame exists in START.
See: http://www.kernel.org/pub/software/scm/git/docs/git-blame.html
It seems you can use git log -L to check file. For example, I want to check the commits for file.c, line from 55 to 60:
git log -L55,60:file.c
You can blame against the specific code string like this.
git log -S 'THE-CODE'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With