DDS
DDS

Reputation: 2478

How to set git not to fiddle with newline on both windows and linux

I'm facing some issue when using a project tracked by git on both windows and linux. As suggested on other questions on windows I have

core.autocrlf=false
core.eol=<blank>

On Linux I have the defaults

core.autocrlf=<blank>
core.eol=<blank>

this is my .gitattributes used in the project

#general rule - ignore eol
* -text

#src
*.c     text diff=cpp
*.cc    text diff=cpp
*.cxx   text diff=cpp
*.cpp   text diff=cpp
*.cpi   text diff=cpp
*.c++   text diff=cpp
*.hpp   text diff=cpp
*.h     text diff=cpp
*.h++   text diff=cpp
*.hh    text diff=cpp
*.CPP   text diff=cpp
*.HPP   text diff=cpp
*.cs    text eol=crlf

# Unix files (LF)
*.sh            text eol=lf
Makefile        text eol=lf
makefile        text eol=lf
MAKEFILE        text eol=lf
make*           text eol=lf


# Windows files (CRLF)

*.sln    text eol=crlf
*.csproj text eol=crlf
*.suo    text eol=crlf
*.vbproj text eol=crlf
*.bat    text eol=crlf
*.vcxproj    text eol=crlf
*.vcproj     text eol=crlf
*.dbproj     text eol=crlf
*.fsproj     text eol=crlf
*.lsproj     text eol=crlf
*.wixproj    text eol=crlf
*.modelproj  text eol=crlf
*.sqlproj    text eol=crlf
*.wwaproj    text eol=crlf

*.xproj      text eol=crlf
*.props      text eol=crlf
*.filters    text eol=crlf
*.vcxitems   text eol=crlf

# common binary files
*.png binary
*.jpg binary
*.gif binary
*.com binary
*.exe binary
*.out binary
*.dll binary
*.a binary
*.lo binary
*.so binary
*.lai   binary
*.la    binary
*.slo binary
*.lib binary
*.class binary
*.dylib binary

# Precompiled Headers
*.gch   binary
*.pch   binary

# Ignoring whitespaces changes on edits
*.c -whitespace
*.cs -whitespace
*.cpp -whitespace
*.h -whitespace
*.hpp -whitespace

# Git LFS for big files
*.dll filter=lfs diff=lfs merge=lfs -text
*.pdb filter=lfs diff=lfs merge=lfs -text

# customized merge strategy for configuration files 
.config merge=ours
*.user merge=ours


### From here JAVA ###

*.properties    text auto

# Unix (LF)

*.xml       text
*.java          text diff=java
*.kt            text diff=kotlin
*.groovy        text diff=java
*.scala         text diff=java
*.gradle        text diff=java
*.gradle.kts    text diff=kotlin



# config file merge strategy 
*.iml merge=ours

# Ignores whitespace changes
*.java -whitespace

# Git LFS for big files
*.[jew]ar filter=lfs diff=lfs merge=lfs -text


# Common build-tool wrapper scripts ('.cmd' versions are handled by 'Common.gitattributes')
mvnw            text eol=lf
gradlew         text eol=lf
# Apply override to all files in the directory
*.md linguist-detectable

# Other files handled as text
*.txt       text auto
*.json      text eol=lf
*.yml       text eol=lf
*.yaml      text eol=lf
.git*       text 
*.html      text 
*.htm       text eol=crlf
*.css           text diff=css
*.scss          text diff=css
*.js            text
*.jsp           text
*.jspf          text
*.jspx          text
*.properties    text
*.tld           text
*.tag           text
*.tagx          text

and this is my .editorconfig (But I dont think it is used on windows given I use VS2015)

root = true

[*]
#end_of_line = lf # commented out not to conflict with git
charset = utf-8
insert_final_newline = true

# Makefile using tab
[{Makefile,makefile,MAKEFILE,app.mak,lib.mak}]
indent_style = tab
trim_trailing_whitespace = true

[*.bat]
end_of_line = crlf

[*.{sh}]
end_of_line = lf

[*.{c,h,cpp,hpp,java,php,js,json,sh}]
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
max_line_length = 120

What I'm finding is that on linux also files like project.sln (a visual studio solution) git diff | cat -v reports newline conversion (^M is removed after the lines).

Also all other files are reported as modified (and the only differences are new lines).

How do I avoid linux reporting "fake" changes?

What am I missing?

Upvotes: 0

Views: 44

Answers (0)

Related Questions