How to switch the order of files (original and modified) in Eclipse Compare window? - eclipse

When comparing two files, for example during a commit, Eclipse shows the original version on the right and modified on the left:
However, I would prefer to see the original version on the left and modified on the right. Is it possible?

Eclipse Neon.2 (4.6.2) has a button to swap the views:

You can either swap the views for every compare, as one answer suggests:
Or you can make the swapped order be the default for all compares:
Windows --> Preferences --> General --> Compare/Patch
Select the Text Compare tab, and mark the check-box of Swap left and right

I think it's just depending of which file you're selecting first. I mean, choose a file, and select compare to .. and choose another one. Next choose the second one and compare to the first one, they'll swap in your window :)

This behaviour is influenced by what exactly is compared. When comparing two local files the view is influenced by the first & second selection. If using e.g. GIT the left hand side will always be what is present locally, the currently checked-out branch or local changes - so changing the branch will influence the view. When using SVN it is mostly the same, so left hand locally, right hand remotly.

Related

How to cleanly clipboard copy code from a GitHub.com diff?

Consider the following split view code diff from a browser on GitHub.com:
While looking at this diff, I want to clipboard copy the code from the right-hand side (e.g. in order to paste that snippet into a different project in another window).
However, if I try to use the mouse to select the code on the right-hand side in the usual fashion, the code from both sides ends up selected:
And if I hit Ctrl+C / Cmd+C, I end up with kind of a mess on my clipboard which includes copies of the code from both sides, and all of the + and - indicators, which leaves me with a lot of error-prone manual cleanup to do after I paste. (Particularly when copying from a diff that's more long and complex then the simple one I picked out for illustration purposes in this question!)
My question: How can I cleanly and easily copy code from one side of a split view diff in a web browser on GitHub.com to my clipboard?
Update March 2021: this should be, this time, supported:
Copy one side of split diff
When comparing changes to a file using the split view, you can now select and copy just one side of the diff.
Previously both sides were copied. Selecting over a comment will still copy the comment's contents.
May 2018:
As mentioned by Hugo Giraudel in his tweet in late April 2018, a bit too quickly:
GitHub finally moved the + and - symbols from diffs to CSS pseudo-elements, making it possible to copy code directly from a diff without having to clean it up.
That is long overdue and fantastic. ✨
Actually... this is only true with the help of third-party extension!
Like sindresorhus/refined-github.
Without, you would still copy the '+' and '-'.
GitLab has that feature though.
This is still pending for BitBucket (issue 16204)
timotheecour reports in the comments that it does not help with side-by-side diffs:
the code from both sides ends up selected
This is in the context of using refined-github, a Browser extension that simplifies the GitHub interface: issue 2765.
Update Nov. 2020: that issue just got resolved with PR 3698

How to undo / redo selective parts of code?

I am using Eclipse.
It happens a lot when we develop code like this (assume it is developed sequentially, from top to bottom):
Part 1 (*)
Part 2
Part 3
Part 4 (*)
Part 5
But we just figured out that parts 1 and 4 (marked with (*)) are wrong and the others are just fine. The question is that how we can undo just those two parts (1 and 4) without undoing the rest?
If we could undo selectively, it was great. Note that simply reverting the code to the version 1 loses parts 2, 3 and 5 which are correct parts and should remain in the code. Also note that usually these parts are mixed in one or two code blocks (not in separate blocks).
Example:
Part 1: Add method f1(x, y) and move some code from main() to f1() --> incorrect (should be reverted)
Part 2: Add method f2(a, b, c, d) --> correct (should remain)
Part 3: Change another part of main() implementation --> correct (should remain)
Part 4: Change f2 signature to f2(s, n) --> incorrect (should be reverted)
Part 5: Change body of f2 --> correct (should remain)
The current approach I use is:
Keeping a copy of the latest version somewhere (e.g., in a temporary
text file), then undo to before part 1, and add those correct parts
from the temporary text file to the source code.
Manual comparison of different versions, and resolving conflicts.
Does anybody think of easier, yet more automatic way of selecting which change to undo and which one to keep?
Eclipse keeps a history of your changes for a few days (configured in the Preferences in 'General > Workspace > Local History'). You can right click on a file and select 'Compare With > Local History' to see the differences between two version of your file. You can copy changes from the old version to the current version.
For the longer term you should use a version control system such as SVN or GIT. There are Eclipse plugins for these which let you do similar 'Compare With' operations - but covering the entire history of the file (provided you commit your changes regularily).
I just found this paper:
Supporting Selective Undo in a Code Editor which will be presented in ICSE 2015 conference.
The authors show the history of changes graphically, so you can choose which changes to undo (and which one to keep).
Azurite (can be download and installed from here) is the name of their implemented Eclipse plugin that supports selective undo and lots of other simple features that are useful for developers.

Is there a key binding for Next Difference and Previous Difference in Eclipse Compare Editor?

In compare editor there are buttons
Next Difference
Previous Difference
Next Change
Previous Change
I'd like to assign key bindings for Next Difference and Previous Difference buttons. However in preferences I see only Select Next Change and Select Previous Change commands (both in category Compare). How can I assign key bindings to buttons referring to differences?
My Eclipse:
Version: Indigo Service Release 2
Build id: 20120216-1857
There are default shortcuts for these:
CTRL-. (next) and CTRL-, (previous)
Next Difference, Previous Difference:
No key mapping (still in Eclipse Neon ) :(
Next Change, Previous Change:
Set "When" to "Comparing in an Editor" worked for me.
In Eclipse Mars, it is still the same process as moeTi explained. I am adding some details. To set custom keyboard shortcuts, go to:
Open Window->Preferences
General->Keys
Here's a list of the commands you would want and the associated mapping:
Previous Difference (Select the previous difference in the comparison editor)
Command 'Previous' in category 'Navigate'
Next Difference (Select the next difference in the comparison editor)
The command 'Next' in category 'Navigate'
Copy Current Change from Right to Left (replace your code with theirs)
The command 'Copy from Right to Left' in category 'Compare'
Copy Current Change from Left to Right (generally not an option)
The command 'Copy from Left to Right' in category 'Compare'

Beyond Compare merges - is there a "take left for all"?

When we do merges with Beyond Compare there is a "Take Left" or "Take Right" option for each conflict.. is there any way to do a "Take Left for all conflicts"? I've seen this in other merge tools (Kidff3 has it) but I can't see it in Beyond Compare.
Change the display filter to Show Conflicts (View->Show Conflicts), then in one of the input panes use Select All (Ctrl+A) followed by Take Left (Ctrl+L) or Take Right (Ctrl+R).
To follow up on what Craig said, Beyond Compare version 3 operates slightly differently. View->Show Conflicts is now View->Show Context.
Also,
Take Left is now Copy to Left (Ctrl+L)
Take Right is now Copy to Right (Ctrl+R)
The two mentioned points could be vexing for someone who reads this with V3, because Take and Copy could be seen as opposites.

What tool can do a visual comparison of two sections within the same file?

Good file comparison tools were already discussed to the pain, but my problem is more exotic. Is there any visual text comparison tool (like WinMerge) that would allow me easily do visual comparison on two sections within the same file?
I have multiple configurations within vcproj file and need to maintain them. It is a pain to do this manually -- splitting windows, scrolling character-by character. On top of that xml is very verbose and takes lots of screen real-estate. I cannot believe there is no tool to do automatic file section comparison, since this sounds like a very common problem.
Please, do not offer me to use property pages, I do not want more complexity, I want less. Splitting manually into files and then comparing them is also too medieval (I am doing this now anyways).
I use Beyond Compare (not free, but I think a shareware version is available). You can select the same file for left and right sides, then right-click the beginning of your section on each side and select "Align Manually". This would allow you to compare two sections of the same file relatively easily.
Overall, I highly recommend the product. I haven't tried version 3, which is what they currently have on their Web site, but version 2 is a fabulous tool. A+
Emacs Ediff.
I use UltraEdit for most of my text editing and they have a product called UltraCompare that does a visual compare.
Update by Mofi
UltraCompare Professional supports also a comparison of text snippets in addition to entire files.
After starting UltraCompare, select Text Compare in menu Mode if not already selected. Select in text editor the first text block which should be compared, press Ctrl+C, switch back to UC and paste with Ctrl+V the block into left text area pane. Switch again to text editor, select the other block in same file, press Ctrl+C, switch back to UC, click into right pane and paste the block with Ctrl+V. The two blocks are immediately compared and the differences are displayed.
Such a text snippet comparison for two blocks in same file can be started also directly from within UltraEdit. Select the first block in file, press Ctrl+C, Ctrl+N, Ctrl+V and Ctrl+A to copy, paste and reselect this block in a new file. Select the second block in file. Execute command Compare from menu File in UltraEdit with option Compare selected text automatically being enabled and click on button Compare. UC Professional is started with just the 2 selected blocks for comparison.
You can use Meld to do this
Open up meld without specifying file names
Meld with prompt which type of comparison you want. Choose file comparison
Meld will present the the icon to select the file names. Below that it will prompt for a Blank comparison. Choose that.
In the file comparison window, paste the sections of the file you want to compare.