Atlassian Bitbucket How To

How to search for commits in Bitbucket Server and Data Center

Bitbucket has greatly improved the development workflow of teams and companies that use Git with its friendly interface and features. However, sometimes it lacks opportunities for the convenient work with commits. Have you ever wasted time scrolling the mouse wheel trying to find some of the old commits? Luckily, there are some ways to make your life easier. In this article you will learn how to find:

  • Projects and repositories in your Bitbucket that a certain user contributed to (filter by author);
  • Commits that were made long ago to a repository with high activity (filter by time);
  • The commits of a user made to a repository or project (filter by author and project/repo);
  • All the commits made to a project (filter by project).

Search for commits via REST API

Bitbucket REST API provides a possibility to get the list of all commits in the repository using this request.

https://example.com/rest/api/1.0/projects/exampleprojectkey/repos/example-repository-slug/commits.

The request can be extended by specific parameters to receive a more accurate result. For instance, since and until options help to get the commits made after or before a certain commit, or between two commits defined by their IDs. Merges parameter controls how to handle merge commits – exclude merge commits, include both merge commits and non-merge commits or only return merge commits.

https://example.com/rest/api/1.0/projects/exampleprojectkey/repos/example-repository-slug/commits?merges=exclude&since=ea3eea9dcbd&until=f4240bf022a

As a result, you receive a JSON response with the list of the commits and their IDs, author’s names and email addresses, commit messages and parents.

{
    "values": [
        {
            "id": "f4240bf022a69815241a883c03645444b58ac553",
            "displayId": "f4240bf022a",
            "author": {
                "name": "Max Desiatov",
                "emailAddress": "max@desiatov.com"
            },
            "authorTimestamp": 1557113671000,
            "committer": {
                "name": "Tomer Doron",
                "emailAddress": "tomer@apple.com"
            },
            "committerTimestamp": 1557113671000,
            "message": "Add internal section link to README.md (#71)",
            "parents": [
                {
                    "id": "ea3eea9dcbd46887d846696261f54b3d2f74fecd",
                    "displayId": "ea3eea9dcbd"
                }
            ]
        },
The information you receive can’t be filtered as it is. You need to create a script that parses this JSON file and then filters the contents by the parameters you choose. For example, if you need to get the commits of a user, filter them by author. Another option is to filter by date if you need to find some of the old or made during a certain time span commits.

This approach has some disadvantages:

  • REST API requests have limits on how many results to return per page. So, in order to get all commits from a repository, you will need to do several requests, then parse them and filter this information. And the more commits in a repo, the more requests you will have to send.
  • If you have large instances with lots of projects and repositories and need to find the commits of a certain user then search through more than one repository will require manual REST API request to each of them separately with the same limit on results per page.
  • It affects Bitbucket performance greatly.

Sourcetree search opportunities

Sourcetree is an Atlassian desktop client for working with Git and Mercurial repositories. It provides an opportunity to search for commits by an author, a commit message and a file.

Its user-friendly interface helps find commits easier, but it’s impossible to look at them for all repositories at once as you need to go to each repo manually. Besides, it needs to be installed on each computer separately and is not available for Linux.

Use Awesome Graphs for Bitbucket App

Awesome Graphs for Bitbucket is a tool that provides statistics for Bitbucket projects and repositories and helps to get insights on the code review process and personal statistics. Convenient search for commits isn’t its main purpose, but a nice bonus.

This app indexes information about commits. Thanks to this, there are no problems with limits and numerous manual queries that appear while using REST API.

Contributions graph shows the activity of each developer during a year as a calendar. So it’s an easy way to find all the commits made by a person to all projects and repositories. It’s also possible to select a time span from a day to a year. Another option is to display the commits for a certain repository when choosing it from the drop-down list or switching to the Detailed view. That helps understand what projects and repositories the user contributed to.

Below the calendar, there is a list of all commits made during the selected time span. By default, it’s a year, but it’s possible to choose any period to display.

In order to find the commits made to a certain repository regardless of their author, use Activity graph. It shows all commits for the last year or a shorter time span in the Activity section below the charts.

And if you need to find commits made long agoTop Committers Report can be a good solution. In general, its use-case is to find the most active contributors of the project or repository, but you can configure the Period of time and choose Authors of the commits you’re searching for.

As a result, it shows the list of all commits for the selected time span in the Activity section below as well as their distribution in time.

Find out what works best for you

We’ve described three ways to work with commits effectively:

  • Bitbucket REST API as an out-of-the-box but a complicated option that can affect Bitbucket performance and is not the most appropriate approach for middle-sized and large companies;
  • Sourcetree as a free application that is suitable for searching among a small number of repositories;
  • Awesome Graphs for Bitbucket add-on as a tool with various analytical features and wide search opportunities.

Try them all and find the best solution!

Recommended Articles