Git 仅忽略 Markdown 文件中的尾随空格

Dev*_*ons 7 git markdown whitespace trailing

我有一个 markdown 文件,其中的行带有尾随空格(这是正确的,应该提交)。我无法将这些更改添加git add -p到索引中,因为 git 抱怨尾随空格。如果我使用它们,它们会被正确添加git add -A,但我希望它能够与git add -p.

我的~/.gitconfig

[core]
  whitespace = trailing-space,space-before-tab
Run Code Online (Sandbox Code Playgroud)

这一直工作得很好,因为在大多数情况下我确实想对尾随空格发出警告(这在 HTML、JS 和 Ruby 文件中是不正确的)。

如何仅忽略 Markdown 文件中的尾随空格?

Suk*_*ima 9

.gitattributes文件中添加以下内容:

*.md  -whitespace
Run Code Online (Sandbox Code Playgroud)

https://git-scm.com/docs/gitattributes#_checking_whitespace_errors

更具体地说,您可以执行以下操作:

*.md  whitespace=space-before-tab
Run Code Online (Sandbox Code Playgroud)

(删除trailing-spaceMarkdown 文件的 。)

.gitattributes以同样的方式处理并将.gitignore其签入存储库。