How do I avoid git-svn and svn CRLF problems such as this one?
Asked Answered
A

1

9

I am using git svn and today I ran into some trouble.

I did an git svn clone and worked on my project for a while. After a few days, I've pushed my work to the svn remote (git svn dcommit). Then I've tried to checkout the project with TortoiseSVN and see if everything is right. Unfortunately, everything was converted to Unix line endings, and VC6 failed to open the project.

So, my git working copy was CRLF, but my svn working copy was LF. I'm assuming git converted it either during git commit or git svn dcommit.

Am I right to assume that I can avoid all this trouble if I set core.autocrlf = false for my git working copy? Will this force git to leave newlines alone? Is there anything else that needs to be done to make git svn easy to use without causing problems for my coworkers?

(It may also be interesting to mention that I have used git svn on the same machine before, without touching the settings, and this was the first time something like this happened.)

Andryc answered 9/8, 2012 at 13:19 Comment(0)
M
1

Subversion has a possibility of EOLs conversion settings for the individual files. And actually Git has it too in a form of .gitattributes files ('text' and 'eol' attributes). For the general case core.autocrlf is not enough.

If you set it to false, all the files with svn:eol-style=native will have LF line ending in git-svn working copy, that is not expected for windows.

If you set it to true, all line endings will be converted to LFs, and will be sent to SVN in a form of LFs (always).

Actually svn:eol-style=unset should correspond to '-text' git attribute (that means no conversion), svn:eol-style=LF --- to 'eol=lf' attribute and svn:eol-style=CRLF --- to 'eol=crlf' attribute; svn:eol-style=native is system dependent, so can be controlled by an unversioned eol setting, so the corresponding git attribute is '!eol' (that would mean get EOL setting from core.eol of .git/config).

Instead of git-svn, you may use any solution that would convert svn:eol-style to the corresponding .gitattirbutes values for individual files and vice versa automatically. One solution is the server-side: you install SubGit into your SVN repository and just use pure Git interface that SubGit will create:

$ subgit install path/to/svn/repository
# Git interface with correct .gtattributes repository will appear at path/to/svn/repository/.git
# you should setup an access to it

Then at the client you clone it and set core.eol to 'crlf' for Windows and to 'lf' for other OS (default value is 'lf').

$ git clone <URL> working_tree
$ cd working_tree
$ git config core.eol crlf #for Windows only

And after that Git will behave in the same manner as SVN.

Alternatively on the client side there's you may use SmartGit: you can clone the SVN repository with it (not open existing git-svn repository) --- and then it will convert svn:eol-style to .gitattributes. No additional core.eol setting is required for this case, SmartGit will care about it.

Maximalist answered 9/8, 2012 at 15:1 Comment(1)
I'm a bit confused by this answer..this is all very useful info, but I think maybe you misunderstood the question. I can't touch anything on SVN, and I can't make people use svn:eol-style, the idea is that no one shoud even know I'm using git. So whatever setting I need to change should be on the git side. Does that help clarify the issue? By the way, the repository I cloned with git svn was empty at the time, all the content came from git after the first dcommit.Andryc

© 2022 - 2024 — McMap. All rights reserved.