84

In netbeans, if I open a file which is under version control the lines which are modified are highlighted in the left. (green for new lines and blue for modified lines)

Is it possible to get a similar effect in Eclipse?

Sudar
  • 18,954
  • 30
  • 85
  • 131
  • Possible duplicate of [Can I setup eclipse to show code changes (I have svn)](http://stackoverflow.com/questions/942082/can-i-setup-eclipse-to-show-code-changes-i-have-svn) – BuZZ-dEE Dec 04 '15 at 13:30

8 Answers8

157
  1. Open the Preferences window
  2. Search for "diff"
  3. Select Quick Diff
  4. Change the "Use this reference source" to a SCM provider (like CVS, SVN or Git)

By default, it compares to the latest version on disk, which, if you've saved the file, is no diff at all. You have to activate the comparison against a SCM repo. I'm not sure what happens if you more than one type of SCM since this is only a single selection.

Dan Allen
  • 2,418
  • 1
  • 16
  • 13
  • 3
    It seems that for Quick Diff to show git diff, the Eclipse project needs to be a git project. Otherwise, Eclipse acts as if you still have "Version on Disk" selected in step 4 above. So, to make it do git diff instead, I had to use "File -> Import -> Git -> Projects from Git" to create a project for the existing code directory. Source for this suggestion: https://www.eclipse.org/forums/index.php/mv/msg/331002/846869/#msg_846869 – cornelius Aug 09 '14 at 21:26
  • 1
    Thanks a lot Dan. OMG .. what a beautiful feature disabled by default! It's working for me for SVN/Subclipse in Eclipse. NOTE: Guys.. Don't expect full lines to be highlighted. The vertical Ruler/ Overview ruler shows the color you chose. – supernova Dec 04 '14 at 16:27
  • @supernova But if you click the ruler colours, it then highlights the text. Which is a bit naff, but vaguely usable. – Duncan Jones Apr 10 '15 at 07:58
  • 1
    When I type in editor or change something I can see highlihted lines with colors, but when I ctrl+s or save file - colors disappear. But I want them to stay while I'm not commit diff, like in Netbeans. How to do it? – Oleg Abrazhaev Jul 13 '16 at 08:05
  • If it does not work, delete the project from the workspace (without deleting the files on disk), then reimport the project. – Geoffrey Jan 19 '17 at 12:46
  • `You have to activate the comparison against a SCM repo` any idea how to do that ? Because when I save the file the colors disappear. – prime Jun 19 '19 at 22:05
  • Note that unlike in Netbeans, if you enable this, unsaved changes do no longer get highlighted. So you cannot have both a Diff to the working copy and a Diff to the latest state of the repository. – Max Oct 02 '19 at 10:12
  • 1
    If it does not work, try to close the project and reopen it. – Jona Dec 02 '20 at 09:11
  • Reopen your editors to actually see it in action. – Rashid Raza Apr 03 '23 at 09:13
5

With Subversive, you can do Team > Show Annotations, and it will annotate the lines with the author and date of the last modification of that line.

thSoft
  • 21,755
  • 5
  • 88
  • 103
  • Thanks. This is more or less what I was looking for. But it would be really great, if it just shows the diff between the current version of the repository and the local changes that I have made. Is it possible to do that? – Sudar Mar 16 '10 at 06:49
  • You can limit the annotations to a range of revisions. Selecting from the last revision to HEAD approximates what you may want (at me, HEAD..HEAD causes Operation failed). – thSoft Mar 16 '10 at 09:41
5

For Eclipse Version: 2019-03 (4.11.0) Go to

  1. Select 'window'
  2. Select 'Preferences'
  3. Go to General -> Editors -> Text Editors -> Quick Diff
  4. Tick 'Enable quick diff'
  5. Tick 'Show differences in overview ruler'
  6. If you want to keep the changes after you save your local copy, then you need to tell the eclipse to compare the local copy with the repository version. To do that change the reference source accordingly.

    enter image description here

prime
  • 14,464
  • 14
  • 99
  • 131
4

Right-click on the file > Team > Show annotation.
A brown tape will appear on the left-side of the code (it represents commited lines), and the modified lines will be shown in white.

Hakim
  • 3,225
  • 5
  • 37
  • 75
4

In Eclipse by using its Quick Diff feature. This is easy to do:

  1. Go to Window -> Preferences -> General -> Editors -> Text Editors -> Quick Diff. This is the dialog from where it can be configured.
  2. Turn on Quick Diff, by enabling the option Enable quick diff.
  3. Choose the version control system for which Quick Diff is needed from the dropdown Use this reference source. Git, SVN and CVS should be present here. Mercurial appears if the MercurialEclipse plugin is installed.
  4. The overview ruler is the ruler to the right of the scrollbar in the editor. If you would like to see the uncommitted lines to be marked on it, enable the option Show differences in overview ruler.
  5. Choose Apply and OK. Close all editor windows and reopen the source file that you want in the editor.

You should be able to see the newly added, modified or deleted lines marked in colors in the left bar on which line numbers are usually displayed. The colors used are the ones set in the Quick Diff dialog (see above steps). You can also view these uncommitted locations marked along the overview ruler on the right.

Vinit Solanki
  • 1,863
  • 2
  • 15
  • 29
3

EGit plugin's Quick Diff does exactly the same as netbans modified lines feature.

http://wiki.eclipse.org/EGit/User_Guide/State

ultra
  • 131
  • 3
2

There are at least two things you must do to get revision-based change highlighting (i.e., ones that do not disappear when the file is saved) to show up in Eclipse's "overview ruler" when using Git:

  1. Prior to import, make sure that Preferences > Team > Git > Projects > Automatically Share project that are located inside Git repositories is checked or import the project into your workspace using Import... > Git > Projects from Git (as pointed out by @cornelius in a comment on another answer)
  2. Enable Quick Diff and select "A Git Revision" as the reference source: Preferences > Editors > Text Editors > Quick Diff
David Avendasora
  • 4,538
  • 1
  • 16
  • 15
  • The part about import is parlty wrong. In most cases; project gets linked to Git even without using the dedicated import wizard. In case it's missing, doing Right-click > Team > Share on Git on the project makes the binding automatically. About the freeze at import, please report it as a bug to http://bugs.eclipse.org with some steps to reproduce. – Mickael Aug 17 '16 at 19:37
  • @Mickael Yeah, sometimes import from Maven does hook-up to git automatically. I have one Eclipse Neon install that correctly connects, and another that doesn't. I haven't been able to track down what the difference is. – David Avendasora Aug 29 '16 at 15:46
  • 1
    Maybe Preferences > Team > Git > Projects > Automatically Share project that are located inside Git repositories? – Mickael Aug 29 '16 at 16:01
  • @Mickael err... um... yeah. I'll edit my answer to reflect that. – David Avendasora Aug 29 '16 at 16:05
0

In eclipse too you will get the line highlighted which is changed util you save the file. and highlight is nothing but the change in color at the left panel of the editor before the start of that changed line.

GuruKulki
  • 25,776
  • 50
  • 140
  • 201
  • I believe the author is looking for a way to see what lines have been changed between project *commits*, instead of between file *saves*. – Benjamin Manns Mar 15 '10 at 14:10
  • As Benjamin mentioned, I was looking for the changes between project commits and not between file saves. – Sudar Mar 16 '10 at 06:50
  • sorry I thought between the saves. But anyways this is also useful for somebody who don't know. – GuruKulki Mar 16 '10 at 07:15