Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Find removed code

You are looking for a variable/method/class name which was in the code once, but which is no longer in the current code.

Which commit removed or renamed it?

git log -G my_name

Difference to -S:

  • -G my_name: find commits where added or removed lines match the regex
  • -S my_name: find commits where the number of occurrences of the exact string changed

I use -G more often for code archaeology, because renames or rewritten lines are easier to find.

Attention: git log -G=foo will search for =foo (and I guess that is not what you wanted).

If you know a co-worker introduced a variable/method/class, but it is not in your code, and git log -G my_name does not help, then you can use git log --all -G my_name. This will search in all branches.