Re: Verbose Commit Ignore Line Fails via CRLF Line Endings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-10-08 at 18:37:47, Spencer Fretwell wrote:
> 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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux