Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which commit removed a particular word/line in GIT

Tags:

git

With both GIT tools and command line, what is the easiest way to find out which commit removed a particular word from a file?

like image 210
Glide Avatar asked Apr 24 '13 00:04

Glide


People also ask

Can git blame show deleted lines?

The report does not tell you anything about lines which have been deleted or replaced; you need to use a tool such as git diff or the "pickaxe" interface briefly mentioned in the following paragraph.

Does git blame identify a particular commit?

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. There are many other options for blame, but generally these could help.

How do I see the commit history of a branch?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.


2 Answers

You could use the methods described in this post:

If you know the contents of the line, this is an ideal use case for:

git log -S<string> path/to/file
git log -G<regex> path/to/file

Or you could try:

git blame --reverse
like image 89
BenC Avatar answered Sep 21 '22 21:09

BenC


git blame will show you the most recent commit that changed each line of a file. You can use that on your file, and then go to the line where your word is.

like image 41
Waynn Lue Avatar answered Sep 21 '22 21:09

Waynn Lue