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

后端 未结 15 1225

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

    Scenario: You did a big clean up of your code by using your IDE. Problem: The IDE cleaned up more than it should and now you code does not compile (missing resources, etc.)

    Solution:

    git grep --cached "text_to_find"
    

    It will find the file where "text_to_find" was changed.

    You can now undo this change and compile your code.

提交回复
热议问题