Saber
Saber

Reputation: 107

How to filter commits with git grep that only starts with a "word"?

I am trying to use 'git log --grep' to only return commits that starts with "word". I have tried 'git log --grep="word"'. However, this returns all commits that contain the string "word" anywhere in the commit message.

Upvotes: 1

Views: 917

Answers (3)

timguy
timguy

Reputation: 2582

For all Windows command line users:

The approved answer wasn't working and even with '^' the word was searched somewhere in the commit message.

This worked for me:

git log --grep="^word" --extended-regexp

Upvotes: 0

Kamol Hasan
Kamol Hasan

Reputation: 13456

  • To grep all commits that start with word, use:

     git log --grep="^word"
    

    Here ^ matches the start of the line.

  • To grep all commits that end with word, use:

    git log --grep='word$'
    

    Here $ matches the end of a line.

  • To grep all commits that contains word as substring, use:

    git log --grep='word'
    

Upvotes: 1

Tobias Thieron
Tobias Thieron

Reputation: 301

The --grep option supports regex. So try the following command: git log --grep="^word"

Upvotes: 3

Related Questions