Articles
Published · November 18, 2026

Find When a Line Left Your Notes With git log -S and -G

A line you wrote is gone from your notes and you don't know when. git log -S finds commits that add or remove a string, and -G finds commits that touch matching lines. Here is how each works, and when to use which.

Also in: Español中文हिन्दी

Run git log -S"the exact text" -p in your notes folder and Git lists every commit that added or removed that text. If you version-control your Markdown notes with Git, that one command usually answers "when did this line disappear?" in a few seconds.

This is called a pickaxe search. Below you'll see how -S works, where -G finds what -S misses, and how to read the result once you have a commit.

Find the commit that removed a line with -S

Say you kept a dentist's phone number in contacts.md and it's gone. You remember part of it. From the notes folder:

git log -S"555-0142" --oneline -p

--oneline keeps each commit to one line, and -p prints the patch under it, so you see the deleted line itself. Add a path after -- to limit the search to one file or folder:

git log -S"555-0142" -p -- contacts.md

The Git documentation says -S looks for differences that change the number of occurrences of the string in a file, which means an addition or a deletion (git-diff options). Git prints newest commits first, which tells you how to read the output. The commit where the count dropped is where the text was removed. The commit where it rose is where it was added. If you see two results, the older one is when you wrote it and the newer one is when you deleted it.

To search every branch instead of only the one you are on, add --all.

What -S counts, and what it ignores

-S is a counter. It compares how many times your string appears in a file before and after each commit, and it only reports commits where that number changed. The gitdiffcore page spells out the consequences. By definition it does not detect in-file moves. And when a commit moves a file wholesale without touching the string, the pair is left out because the count did not change (gitdiffcore).

For your notes, that means:

  • Moving a paragraph up or down inside the same file will not show up with -S.
  • Renaming contacts.md to people.md will not show up either.
  • Editing a different part of the same line will not show up, as long as your string is still there once.

The search string is literal by default. If you need a pattern, add --pickaxe-regex and Git treats the string given to -S as an extended POSIX regular expression. It still counts occurrences, so the limits above still apply.

When -G finds what -S misses

-G takes a regular expression and looks for differences whose patch text has an added or removed line that matches it (git-diff options). It asks whether any matching line was touched, not whether the count changed.

The Git docs illustrate the difference with a commit that replaces hit = frotz(nitfol, mf2.ptr, 1, 0); with return frotz(nitfol, two->ptr, 1, 0);. The docs state that git log -G"frotz\(nitfol" shows that commit, but git log -S"frotz\(nitfol" --pickaxe-regex does not, because the number of occurrences of that string did not change.

Notes behave the same way. Suppose a to-do line changed from - [ ] Renew passport by 2026-03-01 to - [ ] Renew passport by 2026-06-01. The phrase "Renew passport" appears once before and once after, so -S stays quiet. -G catches it:

git log -G"Renew passport" --oneline -p -- todo.md

Use -G when you want every commit that touched a kind of line: every edit to a heading, every change to a dated entry, every time a task was ticked.

If you keep notes in the one sentence per line style, -G hits stay small and readable, because an edit changes one line instead of a whole paragraph.

There is a cost, though. gitdiffcore says -G runs diff twice and greps, which can be quite expensive, and it ignores binary files without textconv filters (gitdiffcore). It also notes that -G will detect in-file moves, which it calls noise. A notes folder is small, so you'll rarely notice. On a large repository, narrow the search with a path.

| | -S"text" | -G"regex" | |---|---|---| | Matches | Commits that change how many times the string appears | Commits with an added or removed line matching the pattern | | Catches a line edited in place | Only if the count changes | Yes | | Catches a move inside one file | No | Yes | | Pattern support | Literal; regex with --pickaxe-regex | Regex always |

Read the change once you find the commit

The -p option makes git log print patch text, so you can usually read the deleted line right in the search result (git-log).

Two flags help when you need more context:

  • --pickaxe-all shows every change in a matching commit, not only the files that contain your string. Handy if you deleted a line during a bigger cleanup and want to see what else moved with it.
  • --follow continues a single file's history beyond renames. The docs say it works only for a single file, so use it as git log --follow -p -- people.md.

Once you have the commit hash, you can view the file as it was just before that commit with git show <hash>^:contacts.md and copy the line back. For prose edits inside a paragraph, git diff --word-diff shows what changed word by word.

Doing this with Carets

A pickaxe search only helps when your notes are plain text files in a Git repository, and that is the setup Carets is built around. Carets is a native notes and code editor for iPhone, iPad, and Mac that works with Markdown, plain text, and code. Your notes stay in files, organized into projects and tags, so a folder you commit is the same folder you edit. Nothing is locked in an app format that Git can't search.

Syntax highlighting for Markdown and code also makes a recovered line easier to spot when you paste it back into a file. Get Carets on the App Store for iPhone, iPad, and Mac.

Frequently Asked Questions

What is the difference between git log -S and -G?

-S finds commits that change how many times a string appears in a file, so it catches additions and removals. -G finds commits whose patch has an added or removed line matching a regular expression, so it also catches lines edited in place.

How do I search with a regular expression using -S?

Add --pickaxe-regex, which makes -S treat its argument as an extended POSIX regular expression. It still counts occurrences, so an in-place edit that keeps the count the same will not show. For that case use -G.

Why does my search miss a note that was renamed?

When you search one file path, add --follow so the history continues beyond renames. Note that -S also leaves out a file that was moved wholesale without changing the string, because the count did not change.

Can I see the whole commit instead of only the matching file?

Yes. --pickaxe-all shows every change in a matching changeset, not just the files that contain the string.