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 [--strip-comments | --comment-lines | --empty-lines]
PARAMETERS
--strip-comments
Strip lines that begin with a # character. These lines will be entirely removed from the output.
--comment-lines
Keep only lines that begin with a # character. All other lines, including blank lines, will be removed. This option cannot be used in conjunction with --empty-lines.
--empty-lines
Keep only empty lines. All other lines, including those with comments or content, will be removed. This option cannot be used in conjunction with --comment-lines.
DESCRIPTION
git-stripspace is a Git plumbing command designed to normalize whitespace in text input. It reads content from standard input and outputs a cleaned version to standard output. Its primary function is to remove leading and trailing whitespace from each line, collapse multiple consecutive blank lines into a single blank line, and ensure that the output ends with exactly one newline character.
This command is primarily used internally by Git itself to ensure consistency in various textual fields, such as commit messages, where whitespace normalization is important for canonical representation and easier parsing. It helps standardize text content before it's processed or stored by Git, contributing to the integrity and predictability of Git's internal data structures.
CAVEATS
This command is a low-level 'plumbing' command primarily intended for internal Git use or advanced scripting. It operates strictly on standard input and writes to standard output, making it suitable for pipelines but not for direct file manipulation without redirection.
The options --comment-lines and --empty-lines are mutually exclusive; only one can be specified at a time.
INPUT/OUTPUT
This command reads from standard input (stdin) and writes its processed output to standard output (stdout). It does not take file paths as direct arguments. Therefore, it is typically used in conjunction with shell redirection (e.g., git stripspace < input.txt
) or in a pipeline (e.g., cat input.txt | git stripspace
).
INTERNAL USE
git-stripspace is not commonly invoked directly by end-users in their daily Git workflow. Instead, it is an internal utility leveraged by higher-level Git commands (e.g., git-commit) to ensure that specific text fields, such as commit messages, are normalized before being stored or used by Git. This ensures that Git can reliably compare and process textual content.
HISTORY
git-stripspace is a fundamental plumbing command within Git, integrated early into its development to handle the critical task of text normalization. Its functionality is vital for internal operations, especially when processing textual metadata like commit messages, where a canonical representation of whitespace is essential for consistency, content hashing, and reliable parsing. While its core purpose has remained constant, it has evolved as part of Git's robust toolkit, ensuring that the system can consistently process and store text data regardless of minor formatting variations in user input.
SEE ALSO
git(1), git-commit(1), git-var(1)