我有一个markdown文件,其中的行有尾随的空格(这是正确的,应该使用逗号)。我无法使用git add -p将这些更改添加到索引中,因为git抱怨尾随空格。如果我使用git add -A,它们的添加是正确的,但我想让它与git add -p一起工作。
我的~/.gitconfig中有
[core]
whitespace = trailing-space,space-before-tab这一直运行良好,因为在大多数情况下,我确实想警告尾随的空格(这在HTML,JS和Ruby文件中是不正确的)。
如何仅忽略Markdown文件中的尾随空格?
发布于 2017-11-16 01:32:58
在.gitattributes中使用它
**/*.md text whitespace=-cr-at-eol,-trailing-space**/*.md whitespace=space-before-tab不工作。在cmd.exe中试用
$ git config --show-origin --get core.whitespace
file:C:/Users/kevin/.gitconfig trailing-space,space-before-tab,cr-at-eol
$ git init .
Initialized empty Git repository in trailing/.git/
$ cat > README.md
Trailing space here:
check it
$ git add README.md
$ git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904
README.md:1: trailing whitespace.
+Trailing space here:
$ echo **/*.md -whitespace > .gitattributes
$ git check-attr --all -- README.md
README.md: whitespace: unset
$ git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904
$ echo **/*.md whitespace=space-before-tab > .gitattributes
$ git check-attr --all -- README.md
README.md: whitespace: space-before-tab
$ git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904
README.md:1: trailing whitespace.
+Trailing space here:
$ echo **/*.md text whitespace=-cr-at-eol,-trailing-space > .gitattributes
$ git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904https://stackoverflow.com/questions/39752867
复制相似问题