首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Git仅忽略markdown文件中的尾随空格

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

Stack Overflow用户
提问于 2016-09-29 00:23:10
回答 2查看 1.1K关注 0票数 4

我有一个markdown文件,其中的行有尾随的空格(这是正确的,应该使用逗号)。我无法使用git add -p将这些更改添加到索引中,因为git抱怨尾随空格。如果我使用git add -A,它们的添加是正确的,但我想让它与git add -p一起工作。

我的~/.gitconfig中有

代码语言:javascript
运行
复制
[core]
  whitespace = trailing-space,space-before-tab

这一直运行良好,因为在大多数情况下,我确实想警告尾随的空格(这在HTML,JS和Ruby文件中是不正确的)。

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

EN

Stack Overflow用户

发布于 2017-11-16 01:32:58

.gitattributes中使用它

代码语言:javascript
运行
复制
**/*.md text whitespace=-cr-at-eol,-trailing-space

**/*.md whitespace=space-before-tab不工作。在cmd.exe中试用

代码语言:javascript
运行
复制
$ 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 4b825dc642cb6eb9a060e54bf8d69288fbee4904
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39752867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档