How to find the commit that added certain data to a file

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the git category.

Last Updated: 2024-04-25

I removed the information for episode #25 from my episodes.json file and later wanted to recover that data.

Here is how I did it:

git log -S'25' -- episodes.json

This command searches the changes within each commit that affect the count of string given with -S. Looks at binary files too.

The output looked a bit like this:

mmit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Author: Jack Kinsella <151206+jackkinsella@users.noreply.github.com>
Date:   Sun Oct 25 11:54:58 2020 +0100

    Prepare episode for release

commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Author: Jack Kinsella <151206+jackkinsella@users.noreply.github.com>
Date:   Sun Sep 13 13:20:13 2020 +0200

    Add next episodes

Then I could check those commits