Skip to main content
  1. Posts/

Find Line History in Git

··152 words·1 min·

When we are working on a real project, we may want to know from which commit a particular line is introduced.

We can use the following git-log command to find:

git log -S "search term"

For example, to find when the line foo = foo + bar was introduced, we may use the following command:

git log -S "foo = foo + bar"

It will find the commit that created this line.

Another similar command is git-blame, for example, to find which commit introduced line 100, we can use the following command:

git blame -L 100,100

In fact, git-blame shows the most recent change to this line. So if this line has been updated since its creation, for example, you have removed the trailing white spaces or renamed variables in this line, git-blame does not work.

Ref:

Related

Git line ending config
·450 words·3 mins
How to Use The Git-tag Feature
··285 words·2 mins
How To Install Latest Version of Git on Linux
··247 words·2 mins