`git -S` doesn't find all commits

58 views Asked by At

Consider the following typescript:

$ git clone [email protected]:laravel/framework.git
$ cd framework

$ git log --all --oneline --graph --decorate
...
| * | | | | | 07bb4d7 fix
| * | | | | | 0c2b7da Use the current timestamp as a default.
| * | | | | | 26cd65e (tag: v5.2.7) increment version

$ git show 0c2b7da
commit 0c2b7da2635f7bbbaf63d1b93fa817232bdd9d65
Author: Taylor Otwell <[email protected]>
Date:   Thu Jan 7 08:01:39 2016 -0600

    Use the current timestamp as a default.

diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php
index fca8e89..7e179aa 100755
--- a/src/Illuminate/Database/Schema/Blueprint.php
+++ b/src/Illuminate/Database/Schema/Blueprint.php
@@ -791,9 +791,9 @@ class Blueprint
      */
     public function timestamps()
     {
-        $this->timestamp('created_at');
+        $this->timestamp('created_at')->useCurrent();

-        $this->timestamp('updated_at');
+        $this->timestamp('updated_at')->useCurrent();
     }

     /**

$ git log -p -m --full-history 07bb4d7 -Stimestamp src/Illuminate/Database/Schema/Blueprint.php

You won't see this commit in the output of the last command. But if you do:

$ git log -p origin/master -Stimestamp src/Illuminate/Database/Schema/Blueprint.php

You'll see this one:

commit 720a116897a4cc6780fa22f34d30c5986eafc581
Author: Taylor Otwell <[email protected]>
Date:   Wed Feb 3 08:13:22 2016 -0600

    make timestamps nullable by default

diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php
index fca8e89..6cfab6f 100755
--- a/src/Illuminate/Database/Schema/Blueprint.php
+++ b/src/Illuminate/Database/Schema/Blueprint.php
@@ -779,9 +779,7 @@ class Blueprint
      */
     public function nullableTimestamps()
     {
-        $this->timestamp('created_at')->nullable();
-
-        $this->timestamp('updated_at')->nullable();
+        return $this->timestamps();
     }

     /**
@@ -791,9 +789,9 @@ class Blueprint
      */
     public function timestamps()
     {
-        $this->timestamp('created_at');
+        $this->timestamp('created_at')->nullable();

-        $this->timestamp('updated_at');
+        $this->timestamp('updated_at')->nullable();
     }

     /**
@@ -803,9 +801,9 @@ class Blueprint
      */
     public function timestampsTz()
     {
-        $this->timestampTz('created_at');
+        $this->timestampTz('created_at')->nullable();

-        $this->timestampTz('updated_at');
+        $this->timestampTz('updated_at')->nullable();
     }

     /**

What am I doing wrong? How do I find commits that change method timestamps?

1

There are 1 answers

0
torek On BEST ANSWER

From the documentation for git log (but with my emphasis added):

-S<string>

       Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file. Intended for the scripter’s use.

The commit not shown has the same number of occurrences of the word timestamp in both versions (before the change, and after). The actual use of the word is different, but the number of occurrences is the same.

The commit that is shown changes the number of occurrences: the first diff-hunk replaces two copies of the word timestamp with just one copy of the word timestamp (two literal timestamp words are replaced with one timestamp-inside-the-word-timestamps).

You almost certainly want, instead, the -G flag, which is described immediately below the -S flag. Note that -G takes a regular expression, rather than a simple string, though the word timestamp has no regex characters in it so for this case there is no difference. (But you might want to use --perl-regexp to get full Perl style regular expressions, so that you can search for \btimestamp\b, meaning "the word timestamp but surrounded by non-word characters", i.e., don't match timestamps or thetimestamp or twotimestamps, all of which contain timestamp.)