top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Different diff strategies in add --interactive in GIT

0 votes
285 views

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?

posted Jun 10, 2013 by anonymous

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

1 Answer

0 votes

Making "git add--interactive" read from diff.algorithm is probably a good idea, because the command itself definitely is a Porcelain. We would probably need a way to defeat the configured default for completeness, either:

git add -p --diff-algorithm=default
git -c diff.algorithm=default add -p

but I suspect that a new option to "git add" that only takes effect together with "-p" is probably an overkill, only in order to support the former and not having to say the latter, but I can be persuaded either way.

As long as "git add --diff-algorithm=foo" without "-i" or "-p" option lets the user know it has no effect (error out, give warning and continue, etc. whose details I do not deeply care), that is.

answer Jun 10, 2013 by anonymous
Similar Questions
+1 vote

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.

+1 vote

I have many commits: A, B, C, ..., Z. I plan to do some housekeeping using rebase. One thing I want to do is to reorder Z to be the first commit. However, other commits will be in conflict with Z's changes. I know I can go through and interactively resolve the conflicts manually. But this is tedious and error prone. I would like to be able to mark Z's changes as authoritative while rebasing. That is, I want to tell git, "whenever a commit conflicts with Z (during this rebase operation) I want you to keep Z's changes and ignore the other." Is this possible? Is there another (hopefully better) way to accomplish what I'm trying to do?

+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?

...