LoginSignup
19
18

More than 5 years have passed since last update.

ソースコードの行末スペースをgitコマンドで取る

Posted at

ソースコードの行末スペース

気になる。
どうしよう。でもsedとかIDEの補助を得るようにお願いするのも面倒だよな、という場合、
git stripspaceが使えるような気がする。

git stripspace

git stripspaceにファイルを標準入力に与えてやると
行末スペースを削除する。

before

test.txt
hello world     

hoge
fuga       

moge    


テキストだとわかりづらいのかもしれんので、画像で。

Screen Shot 2015-02-11 at 15.36.45.png

after

git stripspace < test.txtを実行すると...

test.txt
hello world

hoge
fuga

moge

Screen Shot 2015-02-11 at 15.38.37.png

ファイルを上書き保存したい場合

git stripspaceは標準出力に変更内容を出す。
ファイルを上書きしたい場合、moreutilsにあるspongeを利用し、ファイルを上書きする。

Mac OS Xの場合

homebrewを使えばmoreutilsをインストール可能

> brew install moreutils

ファイルの行末スペースを削除しつつ保存

> git stripspace < test.txt | sponge test.txt

で。

行末スペースを削除して欲しい人に実行してもらうようにお願いしよう。

19
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18