Progress:
TIER 2 · MODULE 57· Intermediate

git stripspace

Used by hooks and editors to tidy commit messages.

🎯 What & why

Cleans up trailing whitespace and blank lines on stdin, with optional comment-stripping. Used by Git itself before storing commit messages and ideal for commit-msg hooks and editor plugins.

🧠 Mental model

A small text filter with three jobs: trim trailing spaces on every line, collapse runs of blank lines, and optionally remove or convert comment lines. Reads stdin, writes stdout, never touches files.

🛠️ Synopsis

git stripspace [-s | --strip-comments]
git stripspace [-c | --comment-lines]

🎚️ Switches & options

FlagWhat it does
-s, --strip-commentsRemove lines beginning with the comment character (default #)
-c, --comment-linesPrepend the comment character to every nonblank line
(default)Strip trailing whitespace and collapse multiple blank lines
(stdin/stdout)Always reads stdin, writes stdout - never edits files in place

💡 Use cases

🧪 Examples

Tidy a commit message in a commit-msg hook
git stripspace < "$1" > "$1.tmp" && mv "$1.tmp" "$1"
Strip comment lines too
git stripspace --strip-comments < message.txt
Turn a help blurb into commented-out lines
echo 'Edit above' | git stripspace --comment-lines
Use the configured comment char
git -c core.commentChar=';' stripspace -s < message.txt

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.