Jeff Burdges
Jeff Burdges

Reputation: 4251

Is there a diff & patch for large cut & pastes

Is there a good tool/workflow for making a diff+patch operation "commute" with a large cut & pastes operation between text files?

We've three files source.old, source.new, and destination. We previously copied several text hunks from source.old into destination, but otherwise these files have shared history. We've since edited source.old to produce source.new and suspect the changes appearing in the copied hunks are relevant to destination.

We first automatically identify the copy & pastes either using a copy & paste detecting tool or by specifying specific git commits representing the paste operations on destination. As the copy & paste would be an edited copy, this should describe the copy & paste operations using diff-like context for both source.old and destination, and provide a diff for each copied hunks.

We next create a patch file representing the changes from source.old to source.new that occur within the copied hunks, but where necessary replace the context from source.old with context from destination, and reorder the hunks to match destination. We finally apply the patch interactively picking the relevant changes.

Is there an easy way to do this using diff & patch like tools? If we're talking about cut & paste operations where source and destination live in the same repository, then presumably such tools must exist since one might split a file into multiple shorter files. I've always been careful to spin down my working branches before that sort of restructuring, but presumably git handles such cross file changes okay. What about doing it manually when source and destination live in unrelated repositories?

Upvotes: 0

Views: 74

Answers (1)

Razi Shaban
Razi Shaban

Reputation: 512

Try Unix's diff and patch, which works with diff's output. It seems that it'll do exactly what you want.

Upvotes: 0

Related Questions