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

Re: noob user, want checkins to all be forced to LF terminated lines

From
WBWalter Bright <boost@digitalmars.com>
Date
Jul 31, 2010, 05:14 UTC
Message-ID
<i30bg7$50k$1@dough.gmane.org>
In-Reply-To
<20100731044957.GA8920@burratino>
Jonathan Nieder wrote:
Show 5 quoted lines
> Walter Bright wrote:
> 
>> I've just started with git.
> 
> I thought I saw you here years ago. :)
I've been around, just not in git.
Show 13 quoted lines
>> Exactly what do I put in $HOME/.gitconfig ?
> 
> Well, naturally it depends on what you want to happen.
> 
> If you just want to make sure any new files you commit are tracked
> with simple LF line endings, you can use
> 
> 	[core]
> 		autocrlf = input
> 
> With this setting, Git will not do any munging to files in the work
> tree in any way (unless there is a .gitattributes file requesting to
> do so).

git is installed under Ubuntu, but I'll be checking in files that I edit on both Windows and Ubuntu, so the line endings will vary depending on which platform I last editted the file on. Hence, I want to force them all to be LF upon checkin.

Show 7 quoted lines
> That is an _altruistic_ setting to use.  It ensures you do not pollute
> history with some alternative line-ending, but your own work tree may
> not necessarily match the cleaned up versions you are checking in; so
> if you try to "git add" and then "touch" a file with CRLF line endings
> with this setting enabled, you may be surprised at the result!
> (Though a simple "git checkout file.c" afterwards should fix up the
> line endings in the work tree.)
Show 6 quoted lines
> If you want to make sure text files in the work tree use LF line
> endings and you are using a recent version of Git, use the above
> setting or
> 
> 	[core]
> 		eol = lf

So this changes the file in the repository to lf only, but not in the worktree? That's what I want.

Show 18 quoted lines
> On Unix-y systems, you do not have to do that, since it is the
> default.  On Windows, the "[core] autocrlf" setting is set up
> by default in /etc/gitconfig so you would probably want to
> override that with
> 
> 	[core]
> 		autocrlf = false
> 
> if you are not setting it to input.
> 
> Which files are text files? you may ask.  By default (unless
> autocrlf is enabled), Git treats files as raw data; to get it
> to futz with line endings, you have to declare your text files
> in a file named .gitattributes in the tracked tree.
> 
> 	* crlf
> 	*.jpg -crlf
> 	*.png -crlf
In the tracked tree? The documentation:
http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html#_checking_out_and_checking_in
says it goes in:
  $GIT_DIR/info/attributes, .gitattributes

so I'm confused again. Does .gitattributes go in $GIT_DIR, or in $GIT_DIR/info ? And what if both of those files are there, which one 'wins' ?

Show 7 quoted lines
> The keyword crlf here means “apply line-ending conversions” and
> nothing more.  In particular, it does not represent the preferred
> line ending.
> 
> If everyone for which you want these setting to take effect uses a
> recent version of git, you can write “text” instead of “crlf” if
> you prefer.
git --version says I'm using 1.5.6.3
> Hope that helps,
Yes, it does, thank you!

A final question: where does the repository actually go (so I can back it up)? This is a local thing, I'm not trying to set up a networked or remote repository, so it'll be the default location.

Previous: Jonathan NiederNext: Ilari Liusvaara
Message 3 of 16 in “noob user, want checkins to all be forced to LF terminated lines”
  1. Walter BrightJul 31, 2010
  2. Jonathan NiederJul 31, 2010
  3. Walter BrightJul 31, 2010
  4. Ilari LiusvaaraJul 31, 2010
  5. Walter BrightJul 31, 2010
  6. Ilari LiusvaaraJul 31, 2010
  7. Walter BrightJul 31, 2010
  8. David AguilarJul 31, 2010
  9. Jonathan NiederJul 31, 2010
  10. Walter BrightJul 31, 2010
  11. Ilari LiusvaaraJul 31, 2010
  12. Jonathan NiederJul 31, 2010
  13. Walter BrightJul 31, 2010
  14. Jay SoffianAug 3, 2010
  15. Will PalmerAug 4, 2010
  16. Miles BaderJul 31, 2010

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.