gitgit-log

How to show the change itself using git log pickaxe?


I would like to search git log for a specific string to find where it was modified/deleted/added.

I knew that I can do this using pickaxe (i.e., git log -S"Text")

When I run this command, only the names of the commits where the change has occurred are shown. I also tried git log -G"Text" but no difference.

When I tried git log -p -S"Text", it showed me full comparision between two versions of files.

Is there a way to spot the exact location (line) where the text has been changed/added/deleted?

I checked related posts 1, 2 but didn't answer my question. I'm working on Windows OS.


Solution

  • Git doesn't provide a built-in way to do this, but you could use the capabilities of your pager to find the text. For example, if you're using less, you can run git log -p -G"Text". Then you can search for "Text" in the output of this command by typing /Text. This is by far the easiest way to find what you're looking for.

    There is an alternative, rather ugly way to hack around this which might meet your needs. If you use --word-diff-regex=Text, Git will produce an alternative word-diff format which will highlight from one instance of "Text" to the next, or just the single instance if only one exists. Again, using your pager is going to be a lot nicer and easier to read.