Make git store text files with CRLF line endings with .gitattributes

I’d like git to store text files with the CLRF line ending-style internally, I don’t just want to see such line endings in the working directory (but the WD should also contain CRLF files). What is the .gitattributes configuration that would achieve this?

I need this so the repository can be seamlessly synced with a Mercurial one that also uses CRLF internally (due to the original files being such).

After going over every possible configuration I found online, including here, I couldn’t find a solution that would yield CRLF. The files, in the end, end up being stored as LF. I tried the following .gitattributes file:

* text=
* text eol=crlf

Also tried text=auto, text=crlf and even without the first line, no luck. I also re-clone the repo between changing this.

Thank you.

Edit: literally 5 seconds after I posted this I found another snippet that appears to be working:

*.* -crlf

However I’m unsure what exactly this does. Can somebody confirm please that this is what I want it won’t bite me later?

  • Using Git how do I find changes between local and remote
  • mercurial: apply a bugfix change from stable named branch to dev branch
  • No changes are pushed when using hg-git
  • Rename a committed to branch in Mercurial
  • How can I synchronize closed and open sourced versions of the same tool using Mercurial?
  • Is there anything like svnserve for Mercurial?
  • Hg-Git and the Current Version (2) of Mercurial?
  • Moving from Mercurial to Git and merging with custom changes
  • One Solution collect form web for “Make git store text files with CRLF line endings with .gitattributes”

    You want the opposite of what Git supports natively. Git considers linefeed to be the native internal line ending, and either supports doing no filtering, so lf or crlf are stored depending what the files in the filesystem have, or filtering to convert crlf in files on the filesystem to lf internally, and lf internally to crlf on the filesystem. So none of the eol settings will work for you, since it sounds like you want the opposite; crlf internally, and lf on the filesystem.

    Git also support arbitrary “smudge” and “clean” filters. “smudge” does some transformation that “dirties” the file, and “clean” should do the opposite transformation to clean it up to commit.

    To do this, add the following to your .git/config:

    [filter "dosify"]
            clean = unix2dos
            smudge = dos2unix

    And then in your .gitattributes:

    * filter=dosify

    If you don’t have dos2unix/unix2dos installed, you could instead use:

    [filter "dosify"]
            clean = tr '\\n' '\\r\\n'
            smudge = tr '\\r\\n' '\\n'

    edit: To respond to your edit, -crlf just means that no crlf <-> lf translations will be done in either direction. It won’t translate lf in your working directory to crlf internally, so if you have editors that store lf, but need the data to be crlf internally, it won’t help with that. If you just want to avoid doing any sort of translation, then just * -crlf should work, to avoid having any automatic translation applied. However, not doing any translation is the default if you haven’t ever set any settings like autocrlf (except on Windows, where I believe that autocrlf is the default).

    Git Baby is a git and github fan, let's start git clone.