[Git] 使用 git log 找尋特定作者、或包含特定字串的 commit

[Git] 使用 git log 找尋特定作者、或包含特定字串的 commit

蠻常會需要使用 git log 查看程式碼的歷史,

但除非是很近期的 commit,不然 git log 的結果通常太多,

因此適當的過濾條件就很有幫助了。

 

像是今天遇到一個問題,只記得是自己修的,

但 commit 的訊息也不太確定是什麼 (← 明顯老年痴呆),

這時可以用 git log –author=<作者名> 來查詢,

加上 –pretty=oneline 的話可以只顯示單行,

更容易快速瞄過,找尋可能的目標:

testuser@localhost ~ $ git log --pretty=oneline --author=testuser src

b4810a120e0da473e75841b17e7ba9ec99b3298a Fix pylint error
fce67bc6c524109435c054fd5aafc08b1b8871ba Fix typo
801dda224694a136024204dfbb78af6a533050d1 Update release num to 98

 

當然如果記得 commit 的訊息寫了什麼,是更有幫助的,

像是我們可以找作者是 tom,同時 commit 訊息裡有 qemu 這個字

(用 -i 代表不管大小寫) 的所有歷史:

git log --author tom -i --grep "qemu"

 

這兩招最近就蠻常用的囉~

 

參考資料:version control – How can I view a git log of just one user’s commits? – Stack Overflow

(本頁面已被瀏覽過 3,216 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料