# Quick question: end of lines

6 messages from 2006-02-28 to 2006-03-01. Participants: Emmanuel Guerin, Johannes Schindelin, Martin Langhoff, Junio C Hamano.
Thread: https://gitlist.dev/t/3497

## Emmanuel Guerin, 2006-02-28 18:32

Subject: Quick question: end of lines
Message-ID: <f898cca90602281032n6603bf14q@mail.gmail.com>
URL: https://gitlist.dev/e/f898cca90602281032n6603bf14q%40mail.gmail.com

```
Hi all,

I  began recently to use git, and there is one thing I still do not
know how to do.

Is it possible to checkout sources out of the GIT repository with
Windows style end of lines?
In a manner much like the one Subversion is using?

To be more precise, I need to be able to checkout files on Unix and
Windows, and it is important that the end of lines are set
accordingly.

Thanks for any hints or pointers,

Regards,

Manu

```

## Johannes Schindelin, 2006-02-28 20:07

Subject: Re: Quick question: end of lines
Message-ID: <Pine.LNX.4.63.0602282101530.10710@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0602282101530.10710%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <f898cca90602281032n6603bf14q@mail.gmail.com>

```
Hi,

On Tue, 28 Feb 2006, Emmanuel Guerin wrote:

> Is it possible to checkout sources out of the GIT repository with
> Windows style end of lines?

No.

As far as git is concerned, every versioned file is equal. IMHO this 
decision is good, since

- different handling is more complicated (you have to keep track of the 
file type), and
- it is not really worth doing.

Windows can handle Unix line endings quite properly (with the notable 
exception of notepad.exe), and even Apple has learnt that it might be a 
stupid idea to insist on being different when it's just not worth it.

The only reason I would accept: you have to work with MS-DOS tools. But 
even in this case, I'd rather write a wrapper which converts to DOS line 
endings, executes the tool, and converts back.

Hth,
Dscho

```

## Martin Langhoff, 2006-02-28 20:15

Subject: Re: Quick question: end of lines
Message-ID: <46a038f90602281215n259066b1qe2e6421625b82e75@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90602281215n259066b1qe2e6421625b82e75%40mail.gmail.com
In-Reply-To: <f898cca90602281032n6603bf14q@mail.gmail.com>

```
On 3/1/06, Emmanuel Guerin <emmanuel@guerin.fr.eu.org> wrote:
> To be more precise, I need to be able to checkout files on Unix and
> Windows, and it is important that the end of lines are set
> accordingly.

Why is this important?

(I am thinking: any reasonably good text editor will know how to deal
with unix newlines, but you may have different reasons).


martin

```

## Emmanuel Guerin, 2006-03-01 00:12

Subject: Re: Quick question: end of lines
Message-ID: <f898cca90602281612n777a4f17m@mail.gmail.com>
URL: https://gitlist.dev/e/f898cca90602281612n777a4f17m%40mail.gmail.com
In-Reply-To: <46a038f90602281215n259066b1qe2e6421625b82e75@mail.gmail.com>

```
2006/3/1, Martin Langhoff <martin.langhoff@gmail.com>:
> Why is this important?
>
> (I am thinking: any reasonably good text editor will know how to deal
> with unix newlines, but you may have different reasons).

Actually, you have found the problem. My particular setup is that
Visual Studio is used on Windows. The editor will handle unix end of
lines all right, but tends to insert windows ones when modifications
are made. This leads to files with inconsistent end of lines, and
nightmares with merges. We use Subversion for the moment, and we have
to make sure that all text files are declared properly in svn to avoid
conflicts.

What I begin to realize is that the only possibility probably lies in
using a tool that converts the modified files "on the fly" before
commits. I just want to make sure that no other solution was found by
others facing a similar problem.

Anyway, thanks for the answers,

Emmanuel

```

## Martin Langhoff, 2006-03-01 08:31

Subject: Re: Quick question: end of lines
Message-ID: <46a038f90603010031g31f8bc33xd3f45f2e19950c78@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90603010031g31f8bc33xd3f45f2e19950c78%40mail.gmail.com
In-Reply-To: <f898cca90602281612n777a4f17m@mail.gmail.com>

```
On 3/1/06, Emmanuel Guerin <emmanuel@guerin.fr.eu.org> wrote:
> What I begin to realize is that the only possibility probably lies in
> using a tool that converts the modified files "on the fly" before
> commits. I just want to make sure that no other solution was found by
> others facing a similar problem.

Perhaps a pre-commit hook? Read the documentation (and search the list
archives). I'm pretty sure you can do newline cleanup before commit or
at least newline checks before commits.

There's always the option of filing a bug in MS's bugzilla ;-)

cheers,


martin

```

## Junio C Hamano, 2006-03-01 09:01

Subject: Re: Quick question: end of lines
Message-ID: <7vwtfelerx.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vwtfelerx.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <46a038f90603010031g31f8bc33xd3f45f2e19950c78@mail.gmail.com>

```
"Martin Langhoff" <martin.langhoff@gmail.com> writes:

> On 3/1/06, Emmanuel Guerin <emmanuel@guerin.fr.eu.org> wrote:
>> What I begin to realize is that the only possibility probably lies in
>> using a tool that converts the modified files "on the fly" before
>> commits. I just want to make sure that no other solution was found by
>> others facing a similar problem.
>
> Perhaps a pre-commit hook? Read the documentation (and search the list
> archives). I'm pretty sure you can do newline cleanup before commit or
> at least newline checks before commits.
>
> There's always the option of filing a bug in MS's bugzilla ;-)

You can use .git/hooks/pre-commit hook in the repository the
editor that munges line-termination, to fix things up.

The hook is called with GIT_INDEX_FILE set to the appropriate
index file, so you could "git-diff-index --cached --name-only
HEAD" to obtain the list of files being committed, sanitize the
working tree files and update-index them again before returning
true from the hook.

This is a silly example to standardize on uppercase.

        git-diff-index --cached --name-only HEAD |
        xargs sh -c '
                while case "$#" in 0) break ;; esac
                do
                        perl -p -i -e "\$_ = uc(\$_)" "$1"
                        git-update-index "$1"
                        shift
                done
        ' dummy
        exit 0

```
