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

后端 未结 15 1410

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

    Whenever I find myself at your place, I use the following command line:

    git log -S "" --all --oneline  --graph
    

    Explanation:

    1. git log - Need I write more here; it shows the logs in chronological order.
    2. -S "" - It shows all those Git commits where any file (added/modified/deleted) has the words/phrases I am trying to find without '<>' symbols.
    3. --all - To enforce and search across all the branches.
    4. --oneline - It compresses the Git log in one line.
    5. --graph - It creates the graph of chronologically ordered commits.

提交回复
热议问题