git-stripspace
Remove unnecessary whitespace from git patches
TLDR
Trim whitespace from a file
Trim whitespace and Git comments from a file
Convert all lines in a file into Git comments
SYNOPSIS
git stripspace [-s | -c] [--strip-comments | --comment-lines] [input]
PARAMETERS
-s, --strip-comments
Omit all lines beginning with # (comment stripping).
-c, --comment-lines
Trim leading whitespace from # lines and prefix with # .
DESCRIPTION
The git stripspace command is a Git plumbing utility designed to normalize text input, such as commit messages or patch descriptions, by removing insignificant whitespace and handling comments consistently.
It processes input from standard input (or files in recent versions) as follows:
• Strips trailing whitespace from every line.
• Removes lines consisting solely of whitespace.
• Ensures the output ends with a single LF newline.
This canonicalization makes text suitable for Git's internal use, preventing issues with line ending variations or extraneous spaces that could affect diffs or storage.
With options, it handles comment lines (starting with #):
• -s entirely omits them, useful for cleaning commit messages.
• -c trims leading whitespace from them and prefixes with # , ideal for generating status-like output.
Primarily used internally by commands like git commit, git am, and git rebase, it ensures uniformity in Git's text handling. While not intended for general-purpose editing, it excels at Git-specific text sanitization.
CAVEATS
Intended for Git plumbing; input must end with LF for best results. Does not handle CRLF normalization itself.
EXAMPLE USAGE
Clean commit message:
git stripspace -s < msg.txt > msg.cleaned
Format comments:
git stripspace -c < status.txt
HISTORY
Introduced in Git 1.5.3 (February 2007) by Junio C Hamano. Evolved as a core plumbing tool for consistent text processing in Git workflows, with minor enhancements like file argument support in Git 2.40+.
SEE ALSO
git-commit(1), git-am(1), sed(1)


