Every writer I know has a story about the paragraph they deleted and then wanted back three days later. Mine was a short opening anecdote that I cut because it felt slow. Two edits later the piece had no warmth left, and the anecdote was gone. Undo history doesn't survive closing the editor.
That's the main reason my drafts now live in Git. Not for collaboration or branching strategies. I just want every saved version one command away. I use a tiny part of Git, and these five commands cover nearly all of it.
1. git init: once per project
Each writing project gets a folder, and each folder becomes a repository:
mkdir spring-newsletter
cd spring-newsletter
git init
Git creates a hidden .git folder for the history. My files stay as they are, and I keep writing in whatever editor I like.
2. git add and git commit: save a version with a note
When I finish a session, or before a big change I might regret, I save a snapshot:
git add draft.md
git commit -m "Move the reader question up to the second paragraph"
The message took me longest to get right. Early on I wrote "edits" and "more changes", which are useless when you're hunting for one specific version. Now I describe what changed in the text, the way I'd explain it to an editor:
- "Cut the opening anecdote, start with the problem"
- "Rewrite the ending as a question"
- "Add second example from the interview notes"
A good message is a label on a drawer. Future me opens the right one without checking them all.
3. git diff --word-diff: see what I actually changed
Plain git diff works line by line, which suits code. In prose, a paragraph is often one long line, so changing one word marks the whole paragraph. The word-diff option fixes that:
git diff --word-diff
After tightening one sentence, it shows:
Most mornings I {+still+} start with [-a cup of tea and a blank page.-]{+tea.+}
Removed words sit inside [- and -], added words inside {+ and +}. Without arguments, it compares my file with the last commit, so I run it before committing to catch accidental changes. In a colour terminal, git diff --word-diff=color drops the brackets and shows the changes in red and green instead.
4. git log: find the version I'm looking for
To see the history of a draft:
git log --oneline -- draft.md
6da2b27 Cut the opening anecdote, start with the problem
7ddc92c Rewrite the ending as a question
3c35fc5 First full draft
This is where good messages pay off. But sometimes I only remember a phrase from what I cut. For that, -S finds commits where a piece of text was added or removed:
git log -S "my grandmother's kitchen" --oneline -- draft.md
It lists the commit that added the phrase and the one that removed it. The newer one is the cut I'm after.
5. git show: get an old paragraph back
With the commit in hand, I print the file as it was then, without touching my current draft:
git show 3c35fc5:draft.md
If the commit I found is the one that removed the paragraph, I add ^ to look at the version just before it:
git show 6da2b27^:draft.md
The old file appears in the terminal and I copy the paragraph across. One detail: the path after the colon is relative to the top of the repository. From a subfolder, write ./draft.md instead.
For an entire old version, there's git restore:
git restore --source=3c35fc5 draft.md
Careful: it overwrites the file in your folder, so uncommitted work is lost. I commit first, then restore, so even the version I'm replacing stays in the history.
What I skip
Branches, rebasing, tags. Useful for lots of people, but for one person writing articles they mostly added steps. The only extra I use is pushing to a private remote now and then as a backup.
The habit that matters is committing often with messages that describe the writing. Once that's in place, cutting a paragraph stops feeling risky, and I edit far more boldly.
Top comments (0)