Git

git stripspace

git-stripspace

名称

git-stripspace - 删除不必要的空格

概要

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

描述

从标准输入中读取提交消息,注释,标记和分支描述等文本,并按照 Git 使用的方式进行清理。

没有任何争论,这将会:

  • remove trailing whitespace from all lines

  • collapse multiple consecutive empty lines into one empty line

  • remove empty lines from the beginning and end of the input

  • add a missing \n to the last line if necessary.

在输入完全由空白字符组成的情况下,不会产生输出。

注意:这是为了清理元数据,更喜欢 git-apply [1] 的--whitespace=fix模式来修正版本库中补丁或文件的空白。

选项

-s --strip-comments

跳过并删除所有以注释字符开头的行(默认#)。

-c --comment-lines

在每行上添加注释字符和空白。行将自动以换行符终止。在空行上,只有注释字符会被预置。

示例

鉴于以下带有噪音的输入,$指示行的结尾:

|A brief introduction $ | $ |$ |A new paragraph$ |# with a commented-out line $ |explaining lots of stuff.$ |$ |# An old paragraph, also commented-out. $ | $ |The end.$ | $

使用git stripspace无参数来获取:

|A brief introduction$ |$ |A new paragraph$ |# with a commented-out line$ |explaining lots of stuff.$ |$ |# An old paragraph, also commented-out.$ |$ |The end.$

使用git stripspace --strip-comments获得:

|A brief introduction$ |$ |A new paragraph$ |explaining lots of stuff.$ |$ |The end.$