top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Searching explanation of different diff algorithms in GIT?

+1 vote
398 views

Is there any explanation available of the different merits and drawbacks of the diff algorithms that Git supports?

I'm not satisfied with the default diff but have enough processing power for a slower algorithm that might produce diffs that better show the intention of the edit.

posted Sep 25, 2013 by Anderson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

It is not just question of algorithm, even definition how should most readable diff look like is problematic, for example when large block is rewritten and one line is unchanged then you get diff like

if (x){
- foo
+ bar
} else {
- foo
+ bar
}

but it is better to create following diff as it does not break flow of code.

if (x) {
- foo
-} else {
- foo
+ bar
+} else {
+ bar
}
answer Sep 25, 2013 by Sheetal Chauhan
Similar Questions
0 votes

I've just been trying to use "add -p" to stage some changes which happen to be textually entangled with other changes that I do not want to stage.

It turns out that "git diff --patience" does a really good job splitting this into exactly the hunks I want, but "add --interactive" doesn't let me change the diff algorithm it uses. I tried setting "diff.algorithm" to "patience", but of course add--interactive uses plumbing diff commands that ignore configuration settings.

As a one off, I locally modified add--interactive to unconditionally use patience diff and it has worked perfectly in this case, but I don't want to have to apply a patch if I ever want this behaviour in the future.

I think the first thing to do is read the "diff.algorithm" setting in git-add--interactive and pass its value to the underlying diff-index and diff-files commands, but should we also have a command line parameter to git-add to specify the diff algorithm in interactive mode? And if so, can we simply add "--diff-algorithm" to git-add, or is that too confusing?

+2 votes

Could somebody tell me how to make git rebase -i show diff of squashed commits (for example), like git commit -v does it?

+1 vote

I am trying to grep for git commit msg in git log...once I do git log..the log is really huge? Is there a way to get only the last 100 commits or is there an efficient way to search commit msg in git log?

...