---
title: "search Deleted or modifiied code through git"
author: "夜鸣猪"
date: "2013-02-01T08:01:59Z"
tags: []
categories: ["编程语言"]
slug: "search-deleted-or-modifiied-code-through-git"
draft: false
lastmod: "2013-02-01T08:01:59Z"
id: 1782041
url: "https://hlee.iteye.com/blog/1782041"
---

```java
git log -S<string> path/to/file
```



```java
git log -SFoo -- path_containing_change 
git log -SFoo -- path_containing_change --since=2009.1.1 --until=2010.1.1
```


To search for commit content (i.e., actual lines of source, as opposed to commit messages and the like), what you need to do is:

```java

git grep <regexp> $(git rev-list --all)
```


This will grep through all your commit text for regexp.

Here are some other useful ways of searching your source:

Search working tree for text matching regular expression regexp:


```java
git grep <regexp>
```


Search working tree for lines of text matching regular expression regexp1 or regexp2:


```java
git grep -e <regexp1> [--or] -e <regexp2>
```


Search working tree for lines of text matching regular expression regexp1 and regexp2, reporting file paths only:

```java

git grep -e <regexp1> --and -e <regexp2>
```


Search working tree for files that have lines of text matching regular expression regexp1 and lines of text matching regular expression regexp2:


```java
git grep -l --all-match -e <regexp1> -e <regexp2>
```


Search all revisions for text matching regular expression regexp:


```java
git grep <regexp> $(git rev-list --all)
```


Search all revisions between rev1 and rev2 for text matching regular expression regexp:

```java

git grep <regexp> $(git rev-list <rev1>..<rev2>)
```


If you run OS X, I have written an OS X Dashboard Widget summarizing this (and other Git commands) here.