Git

名称

git-stripspace - 去除不必要的空白

概述

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

描述

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

如果没有任何参数,就会这样:

  • 删除所有行的尾部空白

  • 将多个连续空行折叠为一个空行

  • 删除输入内容开头和结尾的空行

  • 如有必要,在最后一行添加一个缺失的 \n

如果输入完全由空白字符组成,则不会产生任何输出。

注意: 这是用来清理元数据的,请优先使用 git-apply[1] 中的 --whitespace=fix 模式来修正补丁或文件中的空白。

选项

-s
--strip-comments

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

-c
--comment-lines

在每行前添加注释字符和空白。行将自动以换行符结束。对于空行,只会预置注释字符。

实例

给定以下噪音输入,$ 表示一行的结束:

|A brief introduction   $
|   $
|$
|A new paragraph$
|# 带有注释的一行 $
|explaining lots of stuff.$
|$
|# 旧的一段,也被注释掉了。$
|      $
|The end.$
|  $

使用不带参数的 git stripspace 获取:

|A brief introduction$
|$
|A new paragraph$
|# 带注释行$
|explaining lots of stuff.$
|$
|# 旧段落,也已注释。$
|$
|The end.$

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

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

GIT

属于 git[1] 文档

scroll-to-top