Git仅忽略markdown文件中的尾随空格 [英] Git ignore trailing whitespace in markdown files only

查看:149
本文介绍了Git仅忽略markdown文件中的尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a markdown file with lines that have trailing whitespace (which is correct and should be commited). I'm unable to add these changes using git add -p to the index because git complains about trailing whitespace. They are added correctly if I use git add -A, but I want it to work with git add -p.

我在~/.gitconfig中:

[core]
  whitespace = trailing-space,space-before-tab

这一直很好,因为我在大多数情况下都希望警告尾随空格(在HTML,JS和Ruby文件中不正确).

This has been working fine since for the most part I DO want to warn on trailing whitespace (it is incorrect in HTML, JS and Ruby files).

如何仅忽略Markdown文件中的尾部空白?

How do I ignore the trailing whitespace in Markdown files only?

推荐答案

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

In a .gitattributes file add the following:

**/*.md  -whitespace

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

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

More specifically you could instead do the following:

**/*.md  whitespace=space-before-tab

(删除Markdown文件的trailing-space.)

(dropping the trailing-space for markdown files.)

以与.gitignore相同的方式处理.gitattributes并将其检入存储库.

Treat .gitattributes in the same way you do .gitignore and check it into the repo.

这篇关于Git仅忽略markdown文件中的尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆