Line ending woes... :-(

242 views
Skip to first unread message

jo...@creativepost.co.uk

unread,
Nov 28, 2019, 8:20:37 AM11/28/19
to tortoisegit-users
I work mostly on cross-platform projects (usually C++) where the line endings tend to be Linux style (LF only). And needless to say, the non-Windows devs prefer it to stay that way!

My role is usually to manage MSVC development - but MSVC's own projects use the Windows style of CR/LF. This all works fine as long as I never edit an MSVC project.

If I edit a project (but I then need to stash it for some reason) when I later pop it from the stash, TortoiseGit will invariably convert its line endings to the Linux LF style. (i.e. matching the source file standard). Is there any way to stop this from happening? i.e. can TortoiseGit be made to understand that files with certain extensions need LF whereas others need CR/LF ?

Sven Strickroth

unread,
Nov 28, 2019, 9:07:04 AM11/28/19
to tortoisegit-users, jo...@creativepost.co.uk
Hi,

please check out Git attributes.

e.g. https://git-scm.com/docs/gitattributes
--
Best regards,
Sven Strickroth
PGP key id F5A9D4C4 @ any key-server

jo...@creativepost.co.uk

unread,
Nov 28, 2019, 11:19:24 AM11/28/19
to tortoisegit-users
Thanks Sven - I've occasionally noticed that TortoiseGit's GUI settings seem to offer options for AutoCrlf and SafeCrLf (but they never seem to be selectable on my system).

So am I right in thinking that at the moment, I can only do this from a command line?  And if so, what would be the general form of the command to set the EOL attributes for my_file.vcxproj?  Would it look something like this..?

git  -eol  my_file.vcxproj  crlf

Sven Strickroth

unread,
Nov 28, 2019, 1:04:17 PM11/28/19
to tortoise...@googlegroups.com, jo...@creativepost.co.uk
Am 28.11.2019 um 17:19 schrieb jo...@creativepost.co.uk:
> Thanks Sven - I've occasionally noticed that TortoiseGit's GUI settings
> seem to offer options for AutoCrlf and SafeCrLf (but they never seem to
> be selectable on my system).

I'd call AutoCrLf the "old" way to do this. Git attributes are superior.

I suppose you cannot select a specific value, because you have the
"Effective" view enabled. Please see
<https://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html#tgit-dug-settings-hierarchical>.

> So am I right in thinking that at the moment, I can only do this from a
> command line?  And if so, what would be the general form of the command
> to set the EOL attributes for my_file.vcxproj?  Would it look something
> like this..?
> *
> git  -eol  my_file.vcxproj  crlf*
Git attributes is not a command, but a config file. Please see the link
I provided or search for one of the numerous tutorials on this.

jo...@creativepost.co.uk

unread,
Nov 29, 2019, 8:01:40 AM11/29/19
to tortoisegit-users
Okay, let's see if I got it right...

After a bit more reading I created a file called .gitattributes and placed it in the top-level folder for my project.  Because it wasn't replacing any previous file it currently contains only 1 x line:-

*.vcxproj text eol=crlf

and now, if I stash my MSVC project and then pop it back off the stash, my line endings are correctly returned in Windows style (previously, they'd have been in Linux style).

So it looks like I did the right thing (just wanted to check...)

Yue Lin Ho

unread,
Dec 19, 2019, 12:17:58 AM12/19/19
to tortoisegit-users
Reply all
Reply to author
Forward
0 new messages