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).

  • Map of all svn revision numbers <=> git SHA-1 commit hashes
  • Adding plugins from specific revision Github project to the Cordova project
  • Automatically inserting version numbers in Aptana Studio
  • Git refuses to reset/discard files
  • git push a commit that doesn't belong to any branch
  • Have git rerere automatically mark files as resolved?
  • 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?

  • Is a git folder self-contained?
  • Git workflow: merging branches while avoiding repetitive commit messages
  • Why am I unable to specify a relative path in a .gitignore?
  • creating jenkins jobs with ansible
  • Queueing of git post-receive hooks?
  • git: move stash to repository in another directory
  • 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.