Why I get this patch:
@@ -129,8 +132,9 @@ sub _preprocess_message {
sub _process_message {
my ($self, $message) = @_;
- my $method = ref($message)
Git's diff implements a specific variant of the generalized minimal edit distance or string to string edit problem. We're given some initial set of symbols and some final set, and we are told to come up with the fewest edit instructions out of some limited set of edit commands.
In our particular case, the only allowed instructions are "delete symbol" and "add symbol" (there is no "move" allowed, but see below). Moreover, we have no knowledge of what each symbol means, but each "symbol" is a source line.
The two "symbols" are the same if and only if they match exactly, or (with certain end-of-line and/or white-space options turned on) match after stripping some items away (white space or carriage returns, mainly). Our job is to produce the smallest number of "delete" and "insert new" commands.
The diff you show has two "insert"s and one "delete". The diff Git produces also has two "insert"s and one "delete". As far as Git can tell, this makes them equal. The one it chooses is just a matter of which of several "equal" trace-back paths it chooses through a comparison matrix.
The code in git blame
allows a different algorithm that does allow moves. Solving the problem when allowing moves is much harder, so git diff
just doesn't bother. To enable move detection in git blame
, use -M
.
git diff --patience
produces the result that you expect. The method tries hard not to mark lines as added or removed when they did not change. It is not the default because it is computationally expensive. (And when the purpose is to generate a patch that is applied later, it does not matter most of the time whether a diff looks the one way or the other.)