1

I need to perform a specific kind of log using git.

I would like to know how can I find all commits ids that have insertions or deletions using a specific string (like 'my_table', for example) from a beginning date to an end one.

Is possible show the author and the lines changed on the context of the commits who matchs the query?

Someone know how can I do this?

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123
GarouDan
  • 3,743
  • 9
  • 49
  • 75

2 Answers2

3

Use git log -S"string" This will show you all commits where the number of occurances of "string" changed. If you want to see the patch itself add the -p flag or --patch flag.

You an change the output of the log with --pretty, the author can be show using '%an'

git log -S"string" -p --pretty="%an"

For more options and information have a look at tho man pages. They are also available online (https://www.kernel.org/pub/software/scm/git/docs/git-log.html).

Honril Awmos
  • 192
  • 3
  • Thx a lot. This works, but I needed to change a little the question. Do you know how can I do this? – GarouDan Sep 11 '13 at 19:17
  • @GarouDan `git log -S"string" -p` that will also show the author and the commit sha. If you want only the author, the commit sha run and the context `git -p -S"string" --pretty="%H %an"`. It is all there in the man pages https://www.kernel.org/pub/software/scm/git/docs/git-log.html. There are a lot more options you may find interesting. – Honril Awmos Sep 12 '13 at 04:46
  • I think I missread change that to `--pretty="%an"` if you only want the author. – Honril Awmos Sep 12 '13 at 04:47
1

To query the repository's patch contents, use

git log -S<string-pattern> --diff-filter AD.

Optionally add --pickaxe-regex when using -S to enable regular expression patterns.

Alternatively, to search the commit messages for a specific string, use

git log --grep="<message-pattern>" --diff-filter AD

The --diff-filter AD limits results to only commits where the files were Added or Deleted.

Jordan McCullough
  • 2,517
  • 1
  • 14
  • 7