I have a git repository that contains hundreds of commits and several branches. How to search a particular commit that contains a certain string e.g. "helper function"? Ideally, the string can be denoted by a regex.
To filter commits by their commit message, use the --grep flag.
git log -p # Hit '/' for search mode. # Type in the word you are searching.
Git Grep. Git ships with a command called grep that allows you to easily search through any committed tree, the working directory, or even the index for a string or regular expression. For the examples that follow, we'll search through the source code for Git itself.
To search the commit log (across all branches) for the given text: git log --all --grep='Build 0051' To search the actual content of commits through a repo's history, use: git grep 'Build 0051' $ (git rev-list --all)
Any git repository contains many files, folders, branches, tags, etc. Sometimes it requires searching the particular content in the git repository using a regular expression pattern. `git grep` command is used to search in the checkout branch and local files.
If Git can’t figure out how to match a function or method in your programming language, you can also provide it with a regular expression (or regex ). For example, this would have done the same thing as the example above: git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c .
git log --grep=<pattern> Limit the commits output to ones with log message that matches the specified pattern (regular expression). Show activity on this post. Try this!
Newer versions of git support git log -G<regex>
:
git log -G'helper.*function' --full-history --all
it will search for the regex in the diff of each commit, and only display commits which introduced a change that matches the regex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With