问题
I'm importing an SVN repository into Git, and I have a lot of files with svn:eol-style
set. SubGit reads those properties and generates a .gitattributes
line for every file.
Is there a way to tell it to use a single-liner for every type of file (i.e. *.java text
or *.java text eol=lf
since we have a style guide rule which mandates that)?
I tried to add the info/attributes
to the repository just before the import, but there's no change in the generated .gitattributes
.
Is there a way to do it?
回答1:
At the moment there's no way to define default rules like *.java test eol=lf
for initial translation, but if you later in a Git branch change .gitattributes
to replace all per-file lines with one *.java test eol=lf
rule, all subsequent Java files with svn:eol-style=LF won't result into new lines, but Java files with other svn:eol-style values will result into additional lines as exceptions to the *.java test eol=lf
rule.
Moreover it is even recommended to have the *.java test eol=lf
rule, because when you create a Java file in Git, .gitattributes
rules are applied to it implicitly, so your newly created Java file will have "eol=lf" automatically and when you push it to Git, SubGit will translate it to svn:eol-style=LF. So this rule would act in the same way as SVN auto-properties.
SubGit doesn't consider info/attributes
file at all, because it is not versioned and exists on local machine only while SubGit works on the server-side level. But you can use info/attributes
on the local machine to override .gitattributes
if you need that on one machine only.
I would also note that you should be careful when you change the .gitattributes
file. When you push such a change to SVN, it will update svn:eol-style for all files for which the effective "eol" attribute value was changed.
One more note: be careful when you set the "eol" attribute for a file with mixed EOLs: change its EOLs to LF first at the Git blob level, or (what would be easier) set the svn:eol-style
property on the SVN side instead, because when you set this property, Subversion automatically fixes file content, but Git doesn't do that.
You've mentioned two patterns, *.java text
or *.java text eol=lf
, but they are actually different. The first one is a particular case of a default * text=auto !eol
rule, unless the Java file contains binary characters (as it doesn't contain the "eol" attribute, the main *-rule will set it to !eol, what corresponds to svn:eol-style=native); so it would be ignored when added. The second one will set svn:eol-style=LF for every Java file added to Git.
Finally, in the future versions, we (the SubGit team) plan to add a possibility to specify default *.java test eol=lf
rules for initial translation or deduce it basing on per-extension statistics, but for now you should add this line manually to every Git branch you work with.
来源:https://stackoverflow.com/questions/33013757/subgit-and-gitattributes