Get info about git word-diff merging lines

167 Views Asked by At

I am trying to build by-line history of file and I got strange behavour in git diff/git log... commands when using --word-diff mode. It sometimes merges some lines.

For example, if old version of file was:

r = ioctl(hdev->control, VHOST_SET_LOG_BASE,
    (uint64_t)(unsigned long)hdev->log);

its being converted to:

r = hdev->vhost_ops->vhost_call(hdev, VHOST_SET_LOG_BASE, hdev->log);

(These lines are from this project distributed with GPL license)

Simple git diff gives me normal output (2 lines deleted, one added), but git diff --word-diff gives me this:

r = [-ioctl(hdev->control,-]{+hdev->vhost_ops->vhost_call(hdev,+}
    VHOST_SET_LOG_BASE, [-(uint64_t)(unsigned long)hdev->log);-]{hdev->log);}

Same output will be emitted in --word-diff=porcelain mode, it's not text-mode bug.

As I'm trying to get by-line history of file, my methods are failing on this piece of git log. I see that git is actually showing me the best human-readable diff, because two lines after editing became one line, but it's not obvious for scripts. So,

  • Is this behaviour intended? (git 1.9.1)
  • If it is, is there a way to get some additional output about these merges (and, if there are, unmerges)? It not, how to find them some other way?
1

There are 1 best solutions below

3
Nick Volynkin On

This looks like what --word-diff is supposed to do. Git splits files to words (with " " as delimiter) and shows minimal chunks. You can see that your lines are always splitted on spaces.

Try using --word-diff-regex=<regex> with endline chars.

As for information about merges: git blame may be useful here.