Find substring in recent commits messages

Asked

Viewed 131 times

1

I’m looking for a substring in the most recent commits from my repository.

I use the command git log -n1 --grep='${subString}'.

But using the flag -nI’m just gonna get the last commit, which is technically the most recent. Ex:

commit 1a1a
Author: Gabriel Hardoim
Date: 2018-08-20 13:30:40

       Esse commit tem a substring

But it can, and probably will, happen that there is more than one commit made recently, which makes the flag -n inefficient.

Ex:

commit 2b2b
Author: Gabriel Hardoim
Date: 2018-08-20 13:40:02

       Esse commit não tem

commit 1a1a                             //Nesse caso, esse é o commit que eu quero.
Author: Gabriel Hardoim
Date: 2018-08-20 13:30:40 

       Esse commit tem a substring

There are still the most common cases, where there are several commits with the substring that I’m looking for.

Ex:

commit 2b2b
Author: Gabriel Hardoim
Date: 2018-08-20 13:40:02

       Esse commit não tem

commit 1a1a                             //Nesse caso, esse ainda é o commit que eu quero.
Author: Gabriel Hardoim
Date: 2018-08-20 13:30:40 

       Esse commit tem a substring

commit 3c3c
Author: Gabriel Hardoim
Date: 2018-08-20 13:20:11

       Esse commit também tem a substring

commit 4d4d                             
Author: Gabriel Hardoim
Date: 2018-08-20 13:13:05 

       Esse commit também não tem

Whereas commits went to the remote repository by the same command git push, what can I do to find a substring in the most recent commit message??

  • git log -1 -p ":/subString"? I’m not sure I understand this very well, but git log allows you to fetch the last commit containing the message, in this case subString

1 answer

2


You can use the/shell/linux terminal grep instead.

git log | grep --context=4 "TEXTO"

A simple git log in conjunction with the linux grep, asking to "group" the results in 4 lines back.

In my local test, you displayed three commits whose descriptive messages had the word searched.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.