Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search git history for a disappeared line?

Tags:

git

I need to search the history of a specific file in a git repository to find a line that is gone. The commit message will not have any relevant text to search on. What command do I use?

Further details: this is the history of my todo list out of our non-stellar task tracking software. I've been keeping it for two years because there's just not enough information kept for me in the software. My commit messages usually have only the task ids, unfortunately, and what I need to do is find a closed task by subject, not by number. Yes, the real solution is better task tracking software, but that is completely out of my hands.

like image 845
skiphoppy Avatar asked Apr 23 '10 16:04

skiphoppy


People also ask

Where can I find git history?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

How do I check my git command history?

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.

What is the git history log?

What does git log do? The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA)


1 Answers

This is a job for the pickaxe!

From the git-log manpage:

-S<string>

Look for differences that introduce or remove an instance of <string>. Note that this is different than the string simply appearing in diff output; see the pickaxe entry in gitdiffcore(7) for more details.

You can of course use further options to narrow it down, for example:

git log -Sfoobar --since=2008.1.1 --until=2009.1.1 -- path_containing_change 

There is also:

-G<regex>

Look for differences whose patch text contains added/removed lines that match . To illustrate the difference between -S --pickaxe-regex and -G, consider a commit with the following diff in the same file:

+ return frotz(nitfol, two->ptr, 1, 0);

...

- hit = frotz(nitfol, mf2.ptr, 1, 0);

While git log -G"frotz\(nitfol" will show this commit, git log -S"frotz\(nitfol" --pickaxe-regex will not (because the number of occurrences of that string did not change).

like image 103
Cascabel Avatar answered Oct 05 '22 23:10

Cascabel