Search code examples
gitgitk

gitk: What is the difference between "adding/removing string" and "changing lines matching"?


In gitk, when searching the commits, there are two options which sound like the same to me - "adding/removing string" and "changing lines matching".

I assume there is still some difference between them?

enter image description here


Solution

  • “Adding/removing string” checks if a commit changes the number of times the string occurs in a file. “Changing lines matching” on the other hand applies the given pattern as a regular expression and finds changes which match the provided regex pattern.

    The corresponding command line options for git log are -S (adding/removing string) and -G (changing lines matching). On the command line, you also have the possibility of -Sstring --pickaxe-regex which will treat the pickaxe string as a regular expression, but only match it, if it is either deleted or added in a commit (but not if it's only part of a changed line).

    git log -G explains it quite well:

    To illustrate the difference between -S<regex> --pickaxe-regex and -G<regex>, consider a commit with the following diff in the same file:

    +    return frotz(nitfol, two->ptr, 1, 0);
    ...
    -    hit = frotz(nitfol, mf2.ptr, 1, 0);
    

    While git log -G"frotz\(nitfol" will show this commit, git log -S"frotz\(nitfol" --pickaxe-regex will not (because the number of occurrences of that string did not change).

    More details can be found in the diffcore-pickaxe documentation.