What needs fixing:
I have a repository containing a single .md
file, which contains an essay I am writing.
I edit the file from a few different computers, one running Linux and a couple running Windows.
Looking at a git diff
in Windows now where I have made some changes, I can see my essay showing as nicely separated lines of text ... all about to be removed and replaced by one long line where what were paragraphs are separated by ^M
s.
I'm aware that ^M
refers to Windows' CLRF line endings.
The diff
result implies that I started the file in Linux (entirely possible; I don't remember) and have since saved it in Windows and that all the line endings have been replaced.
I'd like to be able to open files across both OSs with lines displaying as they should, and have a diff
result that shows line breaks (rather than ^M
placeholders) and only changes to the actual content.
What I've tried:
I have done some background reading, read a nice overview of line-endings and Git settings, and even tried following the commands in another Stack Overflow question.
As it stands I have one .gitattributes
file at the top-level of repository which I've committed to the repository itself. It contains just two lines:
# These files are text and should be normalised (convert Windows' CLRF to LF)
*.md text
I've tried this (source):
git rm --cached -r .
git reset --hard
git add .
git commit -m "Normalize line endings"
And this (source):
git rm --cached -r .
git config core.autocrlf input
git diff --cached --name-only -z | xargs -0 git add
git commit -m "Fixed crlf issue"
In the second case, the last command tells me there is nothing to commit. (I also don't like the idea of changing the core.autoclrf
since I'm trying to do this purely through .gitattributes
, but I'm getting frustrated.)
Happy to answer questions and provide more details. Any ideas where I could be going wrong? Am I missing a step?
-Xignore-all-space
to diff and merge so you'd be less bothered with white space changes (you may want to look for a strategy that only ignores line endings, rather than all space). – Philtre