[search] How can I search for a commit message on GitHub?

Not in a Git repository, but rather in GitHub specifically - how do I search just the commit messages of a specific repository/branch?

This question is related to search github

The answer is


This works well from within Eclipse, until GitHub adds the feature:

Enter image description here

EGit/User Guide, Searching for commits


Here's the quick answer It's possible!!

Simply search like so in the github search box (top left):

repo:torvalds/linux merge:false mmap

i.e:

enter image description here

And here's the results:

enter image description here

Read more here


Using Advanced Search on Github seemed the easiest with a combination of other answers. It's basically a search string builder. https://github.com/search/advanced

For example I wanted to find all commits in Autodesk/maya-usd containing "USD" enter image description here

Then in the search results can choose Commits from the list on the left: enter image description here


As of mid-2019

  1. type your query in the top left search box
  2. hit Enter
  3. click "Commits"

Screenshot:

enter image description here


From the help page on searching code, it seems that this isn't yet possible.

You can search for text in your repository, including the ability to choose files or paths to search in, but you can't specify that you want to search in commits.

Maybe suggest this to them?


You can do this with repositories that have been crawled by Google (results vary from repository to repository).

Search all branches of all crawled repositories for "change license"

"change license" site:https://github.com/*/*/commits

Search master branch of all crawled repositories for "change license":

"change license" site:https://github.com/*/*/commits/master

Search master branch of all crawled twitter repositories for "change license"

"change license" site:https://github.com/twitter/*/commits/master

Search all branches of twitter/some_project repository for "change license"

"change license" site:https://github.com/twitter/some_project/commits


Since this has been removed from GitHub, I've been using gitk on Linux to do this.

From terminal go to your repository and type gitk.

In the middle of the GUI, there's a search box. It provides a good selection of filters:

Search bar

Scope - containing, touching paths, adding/removing string, changing line matching

Match type - Exact/IgnCase/Regexp

Search fields - All fields/Headline/Comments/Committer


The short answer is, you cannot search commit messages directly on github.com the website. For the time being we recommend the local git grep solution others on this thread have proposed.

At one point in time GitHub did offer a git grep style search over commit messages for a single repository. Unfortunately, this approach exposed a denial of service that could render a file server inaccessible. For this reason, we removed git grep searching.

Current back-of-the envelope estimates puts the number of commits in GitHub somewhere around the 80 billion mark. Although Google engineers laugh behind our backs, this is a rather large number of documents to store in ElasticSearch. We'd love to make this dataset searchable, but it is not a trivial project.


Update (2017/01/05):

GitHub has published an update that allows you now to search within commit messages from within their UI. See blog post for more information.


I had the same question and contacted someone GitHub yesterday:

Since they switched their search engine to Elasticsearch it's not possible to search for commit messages using the GitHub UI. But that feature is on the team's wishlist.

Unfortunately there's no release date for that function right now.


Update January 2017 (two years later):

You can now search for commit messages! (still only in the master branch)

https://cloud.githubusercontent.com/assets/1387653/21622772/61a5c7a6-d1bc-11e6-809d-134936a4ac05.gif


February 2015: Not sure that could ever be possible, considering the current search infrastructure base on Elasticsearch (introduced in January 2013).

As an answer "drawing from credible and/or official sources", here is an interview done with the GitHub people in charge of introducing Elasticsearch at GitHub (August 2013)

Tim Pease: We have two document types in there: One is a source code file and the other one is a repository. The way that git works is you have commits and you have a branch for each commit. Repository documents keep track of the most recent commit for that particular repository that has been indexed. When a user pushes a new commit up to Github, we then pull that repository document from elasticsearch. We then see the most recently indexed commit and then we get a list of all the files that had been modified, or added, or deleted between this recent push and what we have previously indexed. Then we can go ahead and just update those documents which have been changed. We don’t have to re-index the entire source code tree every time someone pushes.

Andrew Cholakian: So, you guys only index, I’m assuming, the master branch.

Tim Pease: Correct. It’s only the head of the master branch that you’re going to get in there and still that’s a lot of data, two billion documents, 30 terabytes.

Andrew Cholakian: That is awesomely huge.

[...]

Tim Pease: With indexing source code on push, it’s a self-healing process.
We have that repository document which keeps track of the last indexed commit. If we missed, just happen to miss three commits where those jobs fail, the next commit that comes in, we’re still looking at the diff between the previous commit that we indexed and the one that we’re seeing with this new push.
You do a git diff and you get all the files that have been updated, deleted, or added. You can just say, “Okay, we need to remove these files. We need to add these files, and all that.” It’s self-healing and that’s the approach that we have taken with pretty much all of the architecture.

That all means not all the branches of all the repo would be indexed with that approach.
A global commit message search isn't available for now.
And Tim Pease himself confirms commit messages are not indexed.

Note that it isn't impossible to get one's own elasticsearch local indexing of a local clone: see "Searching a git repository with ElasticSearch"

But for a specific repo, the easiest remains to clone it and do a:

git log --all --grep='my search'

(More options at "How to search a Git repository by commit message?")


You used to be able to do this, but GitHub removed this feature at some point mid-2013. To achieve this locally, you can do:

git log -g --grep=STRING

(Use the -g flag if you want to search other branches and dangling commits.)

-g, --walk-reflogs
    Instead of walking the commit ancestry chain, walk reflog entries from
    the most recent one to older ones.

If you have a local version of the repository, you might want to try this crude shell script I wrote to open the GitHub pages for all commits matching your search term in new tabs in your default browser:

#!/bin/sh
for sha1 in $(git rev-list HEAD -i --grep="$1"); do
    python -mwebbrowser https://github.com/RepoOwnerUserName/RepoName/commit/$sha1 >/dev/null 2>/dev/null
done

Just replace https://github.com/RepoOwnerUserName/RepoName/ with the actual GitHub URL of your repository, save the script somewhere (e.g. as githubsearch.sh, make it executable (chmod +x githubsearch.sh) and then add the following alias to your ~/.bashrc file:

alias githubsearch='/path/to/githubsearch.sh'

Then, from anywhere in your Git repository, just do this at the terminal:

githubsearch "what you want to search for"

and any commits that match your (case insensitive) search term will have their corresponding GitHub pages opened in your browser. (Be warned that if your search term appears in hundreds of commits, this may well crash your browser and eat your PC's CPU for a while.)


This was removed from GitHub. I use:

$git log --all --oneline | grep "search query"

enter image description here

You can also filter by author:

$git log --all --oneline --author=rickhanlonii | grep "search query"