Line break changed in some files using EGit - eclipse

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><fmt:message key="label.link" /></div>
+ <div><fmt:message key="label.link" /></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!

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.

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.

Related

How to ignore a file already committed on GIT repository in Eclipse using EGit?

I try to ignore a committed ".project" file on Eclipse EGit, without deleting it from my Eclipse project nor the repo.
I have this need :
the ".project" file of my Eclipse project must be committed at least
at the begining of the project, so that my co-workers can pull it
when they will "build" their Eclipse workplace
this file could be modified by any of us, but should not be pushed on GIT repo
this file must stay on GIT repo all the time, because a co-worker could have to get back the project at any time
we are working on Windows, so using command-line is a bit off-subject : I seek for help on Eclipse EGit
We are migrating from SVN to GIT : on SVN, we did not had this kind of problem, because we could not commit some files. On GIT, it seems that we have to commit everything we modify so that we do not have conflicts.
Can anybody help me ?
Thank you !
Right-click the file and choose Team > Advanced > Assume Unchanged.
See Eclipse Help - EGit Documentation - EGit User Guide - Reference:
Resources can be flagged "assume unchanged". This means that Git stops
checking the working tree files for possible modifications, so you
need to manually unset the bit to tell Git when you change the working
tree file. This setting can be switched on with the menu action
Team > Assume unchanged and switched back with the menu action Team > No Assume unchanged.
It should be noted that each co-worker must do this once. A server-side Git hook could reject commits changing .project if a co-worker had forgotten to do so.

EGit greying out / not showing commit

I've been running into a wired problem (which has been described (but not solved) here as well:
I used to develop using PyDev and Egit (recent versions, EGit is 3.0.3) with just a local repository. Everything worked fine, I was able to commit, branch, reverse etc. just using the "Team" menue in my PyDev perspective.
Now I added a remote reposisory to host the project and since then, I can not commit to my local repository. File changes are not detected (even worse: I change file A and afterwards all folders are marked as "changed" (having the ">" icon) and no file is recognized as "needing synchronization". The only menu points which are available are "Add to index" (which has no effect) and "Pull" (which says "everything is up to date" - which is true since there is nothing new on the server to pull).
When I use git (either command line or git extensions), I see the changed file as changed and it's offered for staging. I can use plain git to commit, push, etc, everything works as expected and no error messages are shown. I'm just using one branch (master).
Even if I open the "Git Repository Exploring" perspective in Eclipse and got to the tab "Git Staging", the file is listed.
I jus started a new test project with just a local repository (residing in the same git-folder ~/git) and here I can commit as I'm used to... And I added the project to the same repository server - and still everthing works! I can commit, I can push, everything is fine there...
yes, I can work around hat by using git extensions, but I really liked the smooth integraion of git in eclipse. Therefore, all ideas, remarks etc. are very welcome! And yes, I tried restarting eclipse ;o).
Finally!!!
Since everything was working before I added the remote host, amd everything worked in my small toy project, I removed and re-added my remote host using gut bash:
git remote remove origin
git remote add origin git#my_servername:my_repository.git
I suppose some configuration files were corrupted in a very non-obvious way (I checked all config fiels and did not notice anything...)
Sounds like a bug, and you might be able to get it back to a good state by playing around with the plugin setting data.
Located here: ${workspace}/.metadata/.plugins
I highly recommend backing up that whole folder before you start playing around. I have had other eclipse issues that have been resolved by going in here and deleting things.

Git setting eclipse project files as read-only

Hopefully there is some setting in git config for this...
Our project team chooses to store eclipse .project and .classpath settings in the git repository. Now, ignoring wether or not storing these files in the SCM is good or bad -- the problem is when the repository is cloned under windows any filename starting with a dot '.' is set as a system file, making it read-only which causes eclipse to spew errors when trying to update projects.
Could not write file: D:\git\SFP\framework\Auth_Server\.classpath.
D:\git\SFP_convert\framework\Auth_Server\.classpath (Access is denied)
So, how do I stop git from setting files starting with a dot '.' as system/read only?
Git shouldn't change those permission, and dotfiles aren't always considered as "system files" in read-only.
Case in point: a .gitignore present in most repo should be perfectly writable when the repo is cloned, even on Windows.
Git only stores two permissions (755=rwxr.xr.x, 644=rw.r..r..).
One way is to make sure to commit in a repo with git config core.filemode false.
But for a repo which already contains files with the incorrect permission, you need to make a new commit with those same files with the right 755 permission.
You can use a reverse patch or git-meta-cache.
The OP Jon reports:
We are currently using msysgit 1.6.5. upgrading to match the git version on the server (1.7.9) has fixed the problem.
I would recommend also to upgrade to the latest available (1.8.4 Sept. 2013)
This problem occurs when we copy the project from system to other system then some file are automatically hidden.You go in your project directory and in this project directory. some folder and file have a hidden attribute so un-check hidden attribute in all file and folder and now import project.

Anyway to use an external diff editor in Eclipse with EGit?

Is there anyway to configure Eclipse/EGit to use an external diff editor and merge tool when doing differences/merges? I've been looking for a way to use something like BeyondCompare or DiffMerge or Kaleidoscope, but so far haven't found anyway to configure it.
I realize that BC has their own plugin, but it does not work within Egit context (ie: when looking at history and comparing to working tree, etc).
I'm running Eclipse 3.7SR2 (Indigo) and eGit 2.1.0. I've tried putting stuff in my .gitconfig to use external diff tools, but Eclipse still opens the files in its own compare windows.
This is currently not supported by EGit, see bug 356832 which tracks this enhancement and also includes a workaround.
As a workaround, you could try the eclipse plugin "External Compare" (see https://sourceforge.net/projects/externalcompare). This plugin opens the contents of the internal eclipse editor in an external editor.
You can use kdiff3 for GIT merging and diffing in Eclipse:
Follow these steps to set up kdiff3 to merge git conflicts within eclipse :
Let git create a config file
can be skipped if there is already a .gitconfig file in your userdir.
Windows users:
%userprofile% (copy paste in Explorer adress bar)
a file named ".gitconfig" needs to exist there
1.1 open a cmd window, execute:
git config --global --edit
The config file was created.
Open the config file ".gitconfig"
2.1 add the following lines to register kdiff3 as the diff and merge tool for git (customize the paths to you needs):
[difftool "kdiff3"]
path = "C:\Program Files\KDiff3/kdiff3.exe"
#
[mergetool "kdiff3"]
path = "C:\Program Files\KDiff3/kdiff3.exe"
#trustExitCode = true
#
Note: This would be the location to register any other supprted mergetool of your liking.
Create a new "Program" "External Tools Configuration" named "git merge" to execute merges from within eclipse!
3.1 Select the following for the parameters:
Location:
C:\Program Files\Git\bin\git.exe
Working directory:
${git_work_tree}
Arguments:
mergetool --tool=kdiff3
To execute a merge, use the standard eclipse merge and as soon as the workspace shows the conflicted state (red markers on projects visible) you mark a project you wish to merge and start the "external tools configuration" we created in the steps listed above.
The merge will start and the kdiff3 window will pop up.
from now just go along your business and only save the files when you are happy with the merge result, as kdiff will deliver a positive merge feedback if you have saved the file.

Git shows files changed, but EGit does not

Git noob here. Having a hard time figuring out why git shows some files changed, while Eclipse EGit does not.
When I use EGit within Eclipse and view a project, it shows no files changed. There is no little caret next to each file. When I use Git for Windows, or go to the command line and type "git status", it shows that all the files have been modified. When I type "git diff" it shows two different versions of a file, first red, then green, and there appears to be some whitespace differences, but I can't be sure, and I can't figure out how the whitespace changed in every file in the project. (Something here doesn't add up.) "git diff -w" returns nothing. "git config --global apply.whitespace nowarn" does nothing.
I might be having a basic conceptual problem with git.
In any case, why do EGit and the git command line show different results?
EGit understands the notion of Derived resources (e.g. used for generated .class files in JDT). In other words, files in derived resources are not added to version control by default in EGit. However, the command line git client does not know these markers, but relies on .gitignore files to avoid checking in generated files.
To check whether your problematic files are derived, open the file properties dialog (right click on the file in the explorer, and select Properties...), and on the Resources page check for the Derived checkbox (it should be around the middle of the dialog).
It turns out that git is playing games with newlines. It's inexplicable. Bottom line: EGit and the git command line cannot both be used on a Windows box. To get consistency, you have to use one or the other.