3

I'm using Eclipse Juno with EGit 2.0 and I'm having the following problem:

I've just cloned a rather big project using EGit, I haven't edited any file and I have some files to commit. If I check the repository status with git status I see those files as unstaged modifications.

If I do Compare With -> HEAD Revision in eclipse for any of those files I don't see any difference. However, when I do git diff I see things like this:

diff --git a/PortalPlatform/WebContent/WEB-INF/fragment/someFile.jsp b/PortalPlatform/WebContent/WEB-INF/fragment/someFile.jsp
index f883dba..811ad83 100644
--- a/PortalPlatform/WebContent/WEB-INF/fragment/someFile.jsp
+++ b/PortalPlatform/WebContent/WEB-INF/fragment/someFile.jsp
@@ -34,7 +34,7 @@
                                    </c:forEach>
                            </select>
                    </c:if>
-                       <div><a href="reprintLastReceipt"><fmt:message key="label.link" /></a></div>
+                       <div><a href="reprintLastReceipt"><fmt:message key="label.link" /></a></div>^M
            </fieldset>
            <div class="widgetBut">
                    <a class="btn primary submit" href="#"><span><fmt:message key="button.reprint" /></span></a>

It hasn't affected a particular file type, I get the problem with .java, .jsp, .css, .properties and .xml files.

Why did I get those changes in the line breaks only in some files? How do I fix it?

Thanks in advance!

mmutilva
  • 18,688
  • 22
  • 59
  • 82
  • 1
    You should set core.autocrlf to false. See [this question][1] and [this question][2]. [1]: http://stackoverflow.com/questions/1249932/git-1-6-4-beta-on-windows-msysgit-unix-or-dos-line-termination/1250133#1250133 [2]: http://stackoverflow.com/questions/2016673/definitive-recommendation-for-git-autocrlf-settings – Deepak Azad Jul 05 '12 at 02:23

2 Answers2

2

Since EGit 2.0, according to bug 301775, EGit supports core.autocrlf.

It used to set autocrlf to false when creating a repo, but bug 382067 and fix 6316 took care of that, which means it relies on the local or global settings you have in your local Git installation (like msysgit).
And as I have said before, this should always be set to false.

If you need fine-grained control on the EOL of certain files, use core.eol attribute.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Kind of old question but still someone can have a problem (as i had).

EGit Documentation > EGit User Guide > Getting started that can be found here states:

Pointing out the System wide configuration

If you use Git for Windows as a companion to EGit, make sure EGit knows where Git is installed so it can find the "system wide settings", e.g. how core.autocrlf is set. Go to the settings and look under Team>Git>Configuration and then the System Settings tab.

If you selected one of the options to use Git from the Command Line Prompt when you installed Git for Windows, then the location of the system wide settings is filled in with a path and everything is fine. If not, use the Browse button to locate where Git is installed, e.g. C:\Program Files(x86)\Git.

This advice also applies to users of other Git packagings, e.g. Git under Cygwin or TortoiseGit.

Non-Windows users should in theory check this setting, but the system wide settings are usually not used on non-Windows platforms.

So as we can see, EGit looks for git config files to khow how 'autocrlf' is exactly configured. But under Windows it seems it does not find all of them.

This command will show us what config git uses:

git config --list --show-origin

And what git's configs are taken into account in Eclipse we can see in Windows > Preference > Team > Git > Configuration. Here is a problem: Eclipse doesn't see config file located in C:\ProgramData\Git folder where 'autocrlf' option defined.

I ended up by duplicating 'autocrlf' value (true - in my case)

[core]

autocrlf = true

in user '.gitconfig' file located in home directory and everythings worked fine.

See also git on Windows - location of configuration files.

Community
  • 1
  • 1
D.F.
  • 21
  • 2
  • @GerhardBarnard I am wandering why the answer is not an answer? This question and the likes (here on SO and on Eclipse Community Forums) are essentially about how to make collaborate git and EGit on the same repo. I gave the solution that worked for me (and, what important) without any intrusion to the repo itself. I am not seeking "sufficient reputation to be able to comment on any post", I just want to share some knowledge. But you are almost made me to give up with that idea. :) Anyway, I edited the post and added some clarification. Hope it is better now. – D.F. May 05 '18 at 16:48
  • This appears to have been my issue and I believe it is version specific for versions of EGIT/JGit as I did not see this problem in an older edition of Eclipse toolset. Anyway, I followed the advice from this blog post (https://netmikey.wordpress.com/2016/06/01/eclipse-git-mind-your-windows-line-endings/) and set autocrlf globally: `git config --global core.autocrlf true` – peater Nov 22 '19 at 16:43