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

Re: [PATCH v3 2/4] gitfaq: give advice on using eol attribute in gitattributes

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 4, 2024, 05:22 UTC
Message-ID
<xmqqcynt91fe.fsf@gitster.g>
In-Reply-To
<20240704003818.750223-3-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 6 quoted lines
> In the FAQ, we tell people how to use the text attribute, but we fail to
> explain what to do with the eol attribute.  As we ourselves have
> noticed, most shell implementations do not care for carriage returns,
> and as such, people will practically always want them to use LF endings.
> Similar things can be said for batch files on Windows, except with CRLF
> endings.
Sounds good.
Show 9 quoted lines
> Since these are common things to have in a repository, let's help users
> make a good decision by recommending that they use the gitattributes
> file to correctly check out the endings.
>
> In addition, let's correct the cross-reference to this question, which
> originally referred to "the following entry", even though a new entry
> has been inserted in between.  The cross-reference notation should
> prevent this from occurring and provide a link in formats, such as HTML,
> which support that.
Thanks for being forward-looking and extra careful.
> +With text files, Git will generally ensure that LF endings are used in the
> +repository, and will honor `core.autocrlf` and `core.eol` to decide what options
> +to use when checking files out.  You can also override this by specifying a
> +particular line ending such as `eol=lf` or `eol=crlf` if those files must always

"this" being ... Not what gets stored in the object database but what is done to the working tree.

What is being "overridden" is that the earlier two mentioned here are configuration variables that apply to _all_ text files in general, and the attribute mechanism is a way to give settings that are more tailored for each path. I think the reason I found the above a bit hard to understand when I read it for the first time was because it didn't "click" that this paragraph was about configuration giving the general default and attributes overriding it. Perhaps...

    ... are used in the repository.  The `core.autocrlf` and
    `core.eol` configuration variables specify what line-ending
    convention is followed when any text file is checked out.  You
    can also use the `eol` attribute (e.g., "eol=crlf") to override
    which files get what line-ending treatment.
or something?
> +have that ending in the working tree (e.g., for functionality reasons).

I'd strike "(e.g., for functionality reasons)" out, as the next paragraph makes it sufficiently clear.

Show 15 quoted lines
> +For example, generally shell files must have LF endings and batch files must
> +have CRLF endings, so the following might be appropriate in some projects:
>  +
>  ----
>  # 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
>  ----
Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 22 in “Additional FAQ entries”
  1. 0/4 Additional FAQ entriesbrian m. carlson, Jul 4, 2024
  2. 2/4 gitfaq: give advice on using eol attribute in gitattributesbrian m. carlson, Jul 4, 2024
  3. Junio C HamanoJul 4, 2024
  4. brian m. carlsonJul 4, 2024
  5. 3/4 gitfaq: add entry about syncing working treesbrian m. carlson, Jul 4, 2024
  6. Junio C HamanoJul 4, 2024
  7. brian m. carlsonJul 4, 2024
  8. Junio C HamanoJul 6, 2024
  9. 1/4 gitfaq: add documentation on proxiesbrian m. carlson, Jul 4, 2024
  10. 4/4 doc: mention that proxies must be completely transparentbrian m. carlson, Jul 4, 2024
  11. Junio C HamanoJul 4, 2024
  12. Junio C HamanoJul 4, 2024
  13. brian m. carlsonJul 4, 2024
  14. Junio C HamanoJul 6, 2024
  15. brian m. carlsonJul 8, 2024
  16. Jeff KingJul 6, 2024
  17. Junio C HamanoJul 6, 2024
  18. 0/4 Additional FAQ entriesbrian m. carlson, Jul 9, 2024
  19. 1/4 gitfaq: add documentation on proxiesbrian m. carlson, Jul 9, 2024
  20. 3/4 gitfaq: add entry about syncing working treesbrian m. carlson, Jul 9, 2024
  21. 4/4 doc: mention that proxies must be completely transparentbrian m. carlson, Jul 9, 2024
  22. 2/4 gitfaq: give advice on using eol attribute in gitattributesbrian m. carlson, Jul 9, 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.