Eclipse 2020-06是否支持逐行对比与合并功能或插件?
Absolutely, Eclipse 2020-06 does support line-by-line comparison and granular difference merging—this is exactly the kind of scenario the built-in compare tool is tailored for. Here's how to use it to handle your comment-adding task without accidentally introducing unwanted variable changes:
Open the side-by-side compare view
Select bothFile1.javaandFile2.javain the Package Explorer, right-click, and choose Compare With > Each Other. This will open the two files side by side with highlighted differences.Split large change blocks into individual lines
Eclipse groups similar changes into "change blocks" by default, which is why your new comment and theTYPE_1/TYPE_2difference were getting lumped together. To fix this:- Find the change block that includes your new comment and the
map.put(...)line. - Either click the small triangular icon on the left edge of the change block, or right-click the block and select Split Changes. This will break the block into separate, individual line differences.
- Find the change block that includes your new comment and the
Merge only the lines you want
Once split, you'll see your comment line as a separate difference, and theTYPE_1/TYPE_2line as another. Now:- Click the merge arrow (pointing from the file with the comment to the one without) next to just the comment line. This will copy the comment over without touching the
TYPE_*variable line. - Leave the
TYPE_1/TYPE_2difference line untouched—Eclipse won't merge that unless you explicitly tell it to.
- Click the merge arrow (pointing from the file with the comment to the one without) next to just the comment line. This will copy the comment over without touching the
Bonus tip for batch tasks
If you have more than two files to handle, select all relevant files in the Package Explorer, right-click, and choose Compare With > Each Other. This opens a multi-file compare view where you can repeat the split-and-merge process for each pair, which is way faster than editing each file manually.
If you're dealing with a lot of identical comment additions across files, you could also use Eclipse's Find/Replace with a regex to target the lines before map.put(Constants.TYPE_[12], variable); and insert comments in bulk—but the compare tool method is safer because you can visually verify each change before merging.
内容的提问来源于stack exchange,提问作者Nzall

