How to grep (search) committed code in the Git history

后端 未结 15 1209

I have deleted a file or some code in a file sometime in the past. Can I grep in the content (not in the commit messages)?

A very poor solution is to grep the log:

15条回答
  •  一向
    一向 (楼主)
    2020-11-22 06:45

    So are you trying to grep through older versions of the code looking to see where something last exists?

    If I were doing this, I would probably use git bisect. Using bisect, you can specify a known good version, a known bad version, and a simple script that does a check to see if the version is good or bad (in this case a grep to see if the code you are looking for is present). Running this will find when the code was removed.

提交回复
热议问题