用 git log 的 -S 與 -G 找變更記錄

符合 blog 副標題的一篇文章。

之前是拿 BBS 看板來存動畫的記錄,不過自從跑在 FreeBSD 32bits 上的 BBS code 一直沒辦法轉移到 Ubuntu 64bits,就放棄用 BBS 看板管動畫記錄了...

現在是拿 Git 來存動畫記錄,後來發現內建的 git log 搜尋起來比 BBS 方便太多,就回不去了...

以「魔法戰爭」來說:

$ git log -S '魔法戰爭' --pretty=%h | xargs -n1 git show
commit 9a6af4ec77561777b854a7ea44da29e197a9dcc2
Author: Gea-Suan Lin <gslin@gslin.org>
Date:   Mon Apr 7 00:55:49 2014 +0800

    Update.

diff --git a/Anime.txt b/Anime.txt
index 080f94a..cd21e14 100644
--- a/Anime.txt
+++ b/Anime.txt
@@ -42,4 +42,3 @@ Z/X IGNITION                            e01
 銀之匙 Silver Spoon 第二季              e04
 鬼燈的冷徹                              e05
 魔女的使命                              e04
-魔法戰爭                                e11
commit 856a27ab4071fb19ca58de3725cdedf53815894b
Author: Gea-Suan Lin <darkkiller@gmail.com>
Date:   Mon Feb 10 04:46:57 2014 +0800

    Update.

diff --git a/Anime.txt b/Anime.txt
index ddb11ea..e5995eb 100644
--- a/Anime.txt
+++ b/Anime.txt
@@ -22,3 +22,4 @@ WIZARD BARRISTERS~弁魔士賽希爾         e01
 偽戀                                    e02
 天才麻將少女 全國篇                     e05
 鬼燈的冷徹                              e05
+魔法戰爭                                e04

-S 只會列出「出現」與「消失」的時候,而且 -S 後面接的是 string 而非 regex。

如果要找所有與「魔法戰爭」相關的變更,則改用 git log -G,要注意的是後面接的是 regex:

 $ git log -G '魔法戰爭' --pretty=%h | xargs -n1 git show

Git 超好用的... XD

One thought on “用 git log 的 -S 與 -G 找變更記錄”

  1. 用了 git 之後都想說 - 不會用 git (或同時代同級產品) 的都是笨蛋

    特別是還在用 CVS 或 share-folder 的怪人

Leave a Reply

Your email address will not be published. Required fields are marked *