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

后端 未结 15 1409

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

    I took Jeet's answer and adapted it to Windows (thanks to this answer):

    FOR /F %x IN ('"git rev-list --all"') DO @git grep  %x > out.txt
    

    Note that for me, for some reason, the actual commit that deleted this regex did not appear in the output of the command, but rather one commit prior to it.

提交回复
热议问题