git diff -G: Regex pattern to exclude a word

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Members,

TL;DR: Question is - How to use the -G option in git diff to exclude a word?

I'm trying to understand how the -G option in git diff works.
Specifically I'm trying to test a Regex which excludes a word from the
git diff.

Consider the following setup:

    > git diff
    first-file.txt
    @@ -1 +1 @@
    -Lorem Ipsum is simply dummy text.
    +Lorem Ipsum is simply dummy text. tree

    second-file.txt
    @@ -1 +1 @@
    -Lorem Ipsum is simply dummy text.
    +Lorem Ipsum is simply dummy text. ball

Word "tree" is added in the first-file.txt and word "ball" is added in
the second-file.txt.

If I run this `git diff -G "^.*tree.*"`, it shows only the first-file.txt.

    > git diff -G "^.*tree.*"
    first-file.txt
    @@ -1 +1 @@
    -Lorem Ipsum is simply dummy text.
    +Lorem Ipsum is simply dummy text. tree

This is correct because the Regex is checking if textual diff has an
added or a deleted line that includes a word "tree".

Now if I try to exclude the word "tree" with this Regex
"^([^t]|(t[^r])|(tr[^e])|(tre[^e]))*($|(t($|(r($|e$)))))", it should
only show the second-file.txt. But the diff lists both the files.

    > git diff -G "^([^t]|(t[^r])|(tr[^e])|(tre[^e]))*($|(t($|(r($|e$)))))"
    first-file.txt
    @@ -1 +1 @@
    -Lorem Ipsum is simply dummy text.
    +Lorem Ipsum is simply dummy text. tree

    second-file.txt
    @@ -1 +1 @@
    -Lorem Ipsum is simply dummy text.
    +Lorem Ipsum is simply dummy text. ball

So the question is how does the -G option work in this case? And how
to use the -G option to exclude a word?

Thanks,
Raghavendra




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux