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

Re: Verbose Commit Ignore Line Fails via CRLF Line Endings

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 8, 2024, 19:09 UTC
Message-ID
<ZwWDd1_76Z6zH4mP@tapette.crustytoothpaste.net>
In-Reply-To
<CABa71BwtEWS79CZwPOa_Nrh1iMrXRo+hyxNBc5F8GsQiwjdapw@mail.gmail.com>
On 2024-10-08 at 18:37:47, Spencer Fretwell wrote:
Show 10 quoted lines
> On second glance it might involve having a file being committed that
> has CRLF endings in it.
> Committing files with LF only does not produce issue.
> 
> I suspect git either needs to add support for a magic ignore line
> ending with a CRLF,
> or has to sanitize verbose output when that output has CRLF (less ideal)
> 
> Bug originally seen as early as
> [2018](https://superuser.com/questions/1367811/sometimes-git-includes-the-diff-to-commit-message-when-using-verbose)

Ah, yes, that would probably explain it. Your editor is seeing some lines that are CRLF and assuming that the entire file is CRLF, which it should not. In Vim and Neovim, you can do `setl ff=unix` when loading a buffer for `git commit` that will force it to always use Unix line endings, and there's probably some functionality in Sublime Text that lets you force a particular line ending.

What might also help is that if these are intended to be text files, you can set a `.gitattributes` file as outlined in the Git FAQ[0]:

  # By default, guess.
  *	text=auto
  # Mark all C files as text.
  *.c	text
  # Ensure all shell files have LF endings and all batch files have CRLF
  # endings in the working tree and both have LF in the repo.
  *.sh text eol=lf
  *.bat text eol=crlf
  # Mark all JPEG files as binary.
  *.jpg	binary

You can customize the file patterns as you see fit. Once you do that and run `git add --renormalize .` (which you should do in the same commit as adding your `.gitattributes` file) and then commit, your text files will be stored in the repository as LF even though they may have CRLF endings in the working tree, and your diff output won't contain CRLF.

[0] https://git-scm.com/docs/gitfaq#Documentation/gitfaq.txt#recommended-storage-settings
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: Spencer FretwellNext: Spencer Fretwell
Message 3 of 9 in “Verbose Commit Ignore Line Fails via CRLF Line Endings”
  1. Spencer FretwellOct 8, 2024
  2. Spencer FretwellOct 8, 2024
  3. brian m. carlsonOct 8, 2024
  4. Spencer FretwellOct 8, 2024
  5. brian m. carlsonOct 8, 2024
  6. Torsten BögershausenOct 11, 2024
  7. Junio C HamanoOct 11, 2024
  8. brian m. carlsonOct 8, 2024
  9. Torsten BögershausenOct 11, 2024

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.