gitextensions icon indicating copy to clipboard operation
gitextensions copied to clipboard

Filtering git log to exclude commit messages by regex

Open dmaul09 opened this issue 5 years ago • 18 comments

I am looking for the correct regex to use in the Filter box in git extensions (v3.3) to exclude all commits containing a certain phrase, i.e., "[Automation]" To remove the visual clutter of commits I don't care about. Is there a way?

dmaul09 avatar Jun 02 '20 22:06 dmaul09

Exactly

[Automation]

Or

Automation

?

vbjay avatar Jun 03 '20 00:06 vbjay

Provide a sample commit message you would expect to match.

vbjay avatar Jun 03 '20 00:06 vbjay

Start with https://regexr.com/5601t and play with it to see what regex would work.

vbjay avatar Jun 03 '20 00:06 vbjay

image

I want to see all commits EXCEPT those containing the string "[Automation]". Positive matches are working fine, it is coming up with the EXCLUSION regex that is puzzling me.

dmaul09 avatar Jun 03 '20 12:06 dmaul09

That's what the regex does. Look at the tests I wrote. Did you follow the regexr link?

vbjay avatar Jun 03 '20 12:06 vbjay

Thank you, yes. But that regex, when put inside the Filter box of Git Extensions, results in an empty list.

dmaul09 avatar Jun 03 '20 13:06 dmaul09

We might need to adjust the options of the Regex object in our code.

You do know you only include what is between the /'s right?

^((?![Automation]).)*$

vbjay avatar Jun 03 '20 13:06 vbjay

Yes, I did know that. Looks like maybe the negative lookahead option is not understood by the GitExtensions regex object?

dmaul09 avatar Jun 03 '20 15:06 dmaul09

Looks like maybe the negative lookahead option is not understood by the GitExtensions regex object?

that seems to me too. The commit list is empty if using: ^(?!.*\[\bbot\b\]).*$ or: ^((?!\[bot\]).)*$ to exlude: [bot] for author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> repo: [email protected]:dotnet/samples.git

verified this testcase at regex101.com and regexr.com/5601t @vbjay ;-)

Micke3rd avatar Feb 06 '24 09:02 Micke3rd

Git uses Posix BRE by default, any regex in regex101 will not work. https://gist.github.com/CMCDragonkai/6c933f4a7d713ef712145c5eb94a1816

You can use other regex engines https://git-scm.com/docs/git-log#Documentation/git-log.txt---perl-regexp

gerhardol avatar Feb 06 '24 11:02 gerhardol

@gerhardol Could you give a working example because even with the documentation, I don't succeed.

Personally, to only exclude a pattern, I found it easier to pass something like that to the filter box --invert-grep --grep="\[bot\]"

pmiossec avatar Feb 06 '24 12:02 pmiossec

--invert-grep is a much better option than to use a negative filter, even if it should be possible.

There is no GUI for the options. I hope that is not needed and that the dropdown history is sufficient. The box to edit in should be improved though.

gerhardol avatar Feb 06 '24 15:02 gerhardol

Personally, to only exclude a pattern, I found it easier to pass something like that to the filter box --invert-grep --grep="\[bot\]"

ty for the hint @pmiossec , but this string is also leading to an empty window. Maybe Iam using it wrong, we're talking about to place it there, right ? : image

Micke3rd avatar Feb 06 '24 21:02 Micke3rd

Use Commit message , add string "--invert-grep --fixed-strings --author="[bot]"" (without testing)

gerhardol avatar Feb 06 '24 21:02 gerhardol

Use Commit message , add string "--invert-grep --fixed-strings --author="[bot]"" (without testing)

I have made my testing on commit message (it was working well) but didn't know that for author it is no more working since git 2.35 See https://stackoverflow.com/a/70644305/717372

So the solution to exclude an author is to let filtering on "Commit message" in the "filter type" and pass the value --perl-regexp --author="^(?!.*\[bot\]).*$"

pmiossec avatar Feb 07 '24 15:02 pmiossec

Use Commit message , add string "--invert-grep --fixed-strings --author="[bot]"" (without testing)

this does not filter, but ty for the idea.

So the solution to exclude an author is to let filtering on "Commit message" in the "filter type" and pass the value --perl-regexp --author="^(?!.*\[bot\]).*$"

that works, ty ! ..... how expected, what a difference in readability

Micke3rd avatar Feb 08 '24 07:02 Micke3rd

Use Commit message , add string "--invert-grep --fixed-strings --author="[bot]"" (without testing)

this does not filter, but ty for the idea.

Yes, as it is described in the link provided, since git v2.35, --invert-grep is working only on commit message (so on --grep="" parameter) whereas it was working on other parameter --author, committer, ...-- before. But it could still be used to exclude based on commit message because the syntax is a lot easier! (and that's even the answer for the original request.

pmiossec avatar Feb 08 '24 08:02 pmiossec