git - 修剪空白 [英] git - trim whitespace
问题描述
我不小心在我最初的提交中输入了一些空格 - 它在 git diff --color
中显示为红色。
我不一定在寻找一个内置的 git 命令。任何可在Ubuntu上免费使用的外部程序也将受到欢迎。 为了修剪当前目录中所有文件的尾部空白,使用:
sed -i's / [[:space:]] * $ //'*
为了警告未来的空格错误(在标签之前尾部空格和 ),并修补补丁中的空白错误,将以下代码添加到 gitconfig
文件中:
<$ p $
whitespace = fix
I've accidentally put some whitespace in my initial commit - it shows up red in git diff --color
. What's the best way to get rid of the existing whitespace and how can I avoid this happening again?
I am not necessarily looking for a built-in git command. Any external program available for free on Ubuntu would also be welcome.
To trim trailing whitespace on all files in the current directory, use:
sed -i 's/[[:space:]]*$//' *
To warn about future whitespace errors (both trailing spaces and spaces before tabs), and to fix whitespace errors in patches, add the following code to your gitconfig
file:
[core]
whitespace = trailing-space,space-before-tab
[apply]
whitespace = fix
这篇关于git - 修剪空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!