search Deleted or modifiied code through git

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


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:
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:

git grep <regexp>


Search working tree for lines of text matching regular expression regexp1 or regexp2:

git grep -e <regexp1> [--or] -e <regexp2>


Search working tree for lines of text matching regular expression regexp1 and regexp2, reporting file paths only:
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:

git grep -l --all-match -e <regexp1> -e <regexp2>


Search all revisions for text matching regular expression regexp:

git grep <regexp> $(git rev-list --all)


Search all revisions between rev1 and rev2 for text matching regular expression regexp:
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.

你可能感兴趣的:(git)