I needed to edit a messy commit commit that only changed a word in a few subsequent rows, keeping some of those changes and removing others. The changes were easy to see in
I couldn't find a working solution, so I've put together a script that converts word-diff into a regular diff that can be applied:
#!/usr/bin/env perl
# convert-word-diff.pl -- rev. 2, this script is licensed under WTFPLv2
my (@minus, @plus);
sub flush_diff {
print join("", map { "-$_" } @minus);
print join("", map { "+$_" } @plus);
@minus = (); @plus = ();
}
while (my $line = <>) {
if ($line =~ /^(?:index |diff |\+\+\+ |\-\-\- |@@ )/) {
flush_diff();
print $line;
next;
}
my $is_diff_line;
if ($line =~ /\[\-.*\-\]/ || $line =~ /\{\+.*?\+\}/) {
my $copy = $line;
$copy =~ s/\[\-(.*?)\-\]\{\+.*?\+\}/\1/g;
$copy =~ s/\[\-(.*?)\-\] ( )?/ \1 /g;
$copy =~ s/\{\+.*?\+\} ?//g;
push(@minus, $copy);
$copy = $line;
$copy =~ s/\[\-.*?\-\]//g;
$copy =~ s/\{\+(.*?)\+\}/\1/g;
push(@plus, $copy);
$is_diff_line = 1;
}
unless ($is_diff_line) {
flush_diff();
print " $line" ;
}
}
flush_diff();
Usage:
cat word-diff.txt | perl convert-word-diff.pl | git apply
Hopefully I didn't mess up anything and you are on Linux/Mac and have Perl. :-)