2016-09-28 8 views
1

私は後ろに空白がある行を持つマークダウンファイルを持っています(これは正しいものであり、コミットする必要があります)。 gitは末尾の空白について不平を言っているので、私はgit add -pを使ってこれらの変更をインデックスに追加できません。私がgit add -Aを使用した場合、それらは正しく追加されますが、git add -pと動作します。Gitはマークダウンファイル内の末尾の空白を無視します

私は私の~/.gitconfigを持っている:

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

ほとんどの部分は、私は最後の空白に警告したいですので、これは正常に動作している(それはHTML、JSとRubyファイルで間違っています)。

Markdownファイルの末尾の空白を無視するにはどうすればよいですか? .gitattributesファイルで

答えて

0

は、以下を追加します。

**/*.md -whitespace 

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

をより具体的には、あなたが代わりに次の操作を行うことができます:

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

(。値下げファイル用trailing-spaceを落とす)

.gitignoreと同じ方法で.gitattributesを処理し、repoにチェックインしてください。 .gitattributes

0

使用これを:
**/*.md text whitespace=-cr-at-eol,-trailing-space

**/*.md whitespace=space-before-tabは動作しません:

C:\Users\kevin\Documents\trailing>git config --show-origin --get core.whitespace 
file:C:/Users/kevin/.gitconfig trailing-space,space-before-tab,cr-at-eol 

C:\Users\kevin\Documents\trailing>git init . 
Initialized empty Git repository in C:/Users/kevin/Documents/trailing/.git/ 

C:\Users\kevin\Documents\trailing>cat > README.md 
Trailing space here: 
check it 

C:\Users\kevin\Documents\trailing>git add README.md 

C:\Users\kevin\Documents\trailing>git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 
README.md:1: trailing whitespace. 
+Trailing space here: 

C:\Users\kevin\Documents\trailing>echo **/*.md -whitespace > .gitattributes 

C:\Users\kevin\Documents\trailing>git check-attr --all -- README.md 
README.md: whitespace: unset 

C:\Users\kevin\Documents\trailing>git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 

C:\Users\kevin\Documents\trailing>echo **/*.md whitespace=space-before-tab > .gitattributes 

C:\Users\kevin\Documents\trailing>git check-attr --all -- README.md 
README.md: whitespace: space-before-tab 

C:\Users\kevin\Documents\trailing>git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 
README.md:1: trailing whitespace. 
+Trailing space here: 

C:\Users\kevin\Documents\trailing>echo **/*.md text whitespace=-cr-at-eol,-trailing-space > .gitattributes 

C:\Users\kevin\Documents\trailing>git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 
関連する問題