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

后端 未结 15 1212

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 07:05

    Jeet's answer works in PowerShell.

    git grep -n  $(git rev-list --all)
    

    The following displays all files, in any commit, that contain a password.

    # Store intermediate result
    $result = git grep -n "password" $(git rev-list --all)
    
    # Display unique file names
    $result | select -unique { $_ -replace "(^.*?:)|(:.*)", "" }
    

提交回复
热议问题