git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: CRLF, LF ... CR ?

From
Jeff King <peff@peff.net>
Date
Sep 13, 2012, 18:23 UTC
Message-ID
<20120913182344.GA2181@sigill.intra.peff.net>
In-Reply-To
<20120913201720399747.156466ee@gpio.dk>
On Thu, Sep 13, 2012 at 08:17:20PM +0200, Jens Bauer wrote:
Show 13 quoted lines
> In my home directory, I have a .gitconfig file, here's the interesting part:
> [core]
>         editor = nano
>         excludesfile = /Users/jens/.gitexcludes
>         attributesfile = /Users/jens/.gitattributes
> 
> [filter "cr"]
>         clean = tr '\\r' '\\n'
>         smudge = tr '\\n' '\\r'
> 
> 
> In my home directory I added .gitattributes:
> *.osm   filter=cr
Looks right.
Show 7 quoted lines
> Now, when I clone the project, make a change and then issue this command...
> $ git diff mypcb.osm
> 
> ...I get a strange diff. On line 3, one of the files shows a lot of control-m (<cr>) lines.
> After that, I see <lf> lines, all prefixed with a '+', as if they were added.
> 
> I think I might be nearly there, just missing some obvious detail somewhere.

Yes, that's expected. The point of the "clean" filter is to convert your working tree file into a canonical (lf-only) representation inside the repository. But you've already made commits with the cr form in the repository. So you can choose one of:

  1. Make a new commit with these settings, which will have the
     canonical format. Accept that the old history will be funny, but
     you will be OK from here on out.
  2. Rewrite the old history to pretend that it was always LF. This
     gives you a nice clean history, but if you are collaborating with
     other people, they will need to rebase their work on the new
     history. See "git help filter-branch" for details.
-Peff
Previous: Jens BauerNext: Jens Bauer
Message 6 of 18 in “CRLF, LF ... CR ?”
  1. Jens BauerSep 13, 2012
  2. Drew NorthupSep 13, 2012
  3. Jeff KingSep 13, 2012
  4. Jens BauerSep 13, 2012
  5. Jens BauerSep 13, 2012
  6. Jeff KingSep 13, 2012
  7. Jens BauerSep 13, 2012
  8. Johannes SixtSep 13, 2012
  9. Jens BauerSep 13, 2012
  10. Erik Faye-LundSep 13, 2012
  11. David AguilarSep 14, 2012
  12. Jens BauerSep 14, 2012
  13. Junio C HamanoSep 14, 2012
  14. David AguilarSep 26, 2012
  15. Jens BauerSep 26, 2012
  16. Jens BauerSep 26, 2012
  17. Junio C HamanoSep 27, 2012
  18. Jens BauerSep 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.