Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do intelligent diffing between files?

Tags:

diff

I've been making changes that involved moving methods around, extracting new methods, and changing functionality a small amount (not all at the same time, but within the same revision - maybe that was a bad decision).

Conventional diffing seems to generate diffs that report that method doFoo was deleted at line 42, and that an almost identical method that is also called doFoo was created at line 2012. Is it easy to ask a diffing program to compare the doFoo deleted at line 42 with the doFoo created at 2012? (Preferably a diff program that is free and available on Ubuntu)

like image 742
Andrew Grimm Avatar asked Aug 07 '09 08:08

Andrew Grimm


2 Answers

Ediff, the diff tool included with emacs, will help you examine these regions.

You may run into situations when a large chunk of text in one file has been edited and then moved to a different place in another file. In such a case, these two chunks of text are unlikely to belong to the same difference region, so the refinement feature of Ediff will not be able to tell you what exactly differs inside these chunks. Since eyeballing large pieces of text is contrary to human nature, Ediff has a special command to help reduce the risk of developing a cataract.

like image 196
Steven Huwig Avatar answered Sep 17 '22 17:09

Steven Huwig


See SmartDifferencer for a tool that understands language syntax and abstract editing commands such as "move this block of code from line A to line B", "rename this variable everywhere in scope". Presently available for Java and COBOL, other languages following Real Soon.

EDIT 9/4/2009: C# added...

EDIT 5/2011: Many languages added: C++, JavaScript, more... Check site.

like image 33
Ira Baxter Avatar answered Sep 21 '22 17:09

Ira Baxter