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 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).

We’ll also show you how to automate the process using the Bitbucket REST API, as well as the Awesome Graphs REST API and the Export to CSV feature.

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 helps engineering leaders and software teams improve their own processes and deliver products faster by transforming invisible development activities into easy-to-understand insights and reports. Convenient search for commits isn’t its main purpose, but a nice bonus.

This app indexes information about commits, which makes searching by author, time, or repository faster and does not affect even huge Bitbucket instances (70,000+ repositories).

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. Here you can also filter the commits of a particular user by time period (up to a year) and by project or repository.

 

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 ago, Top 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.

Export commit data to CSV

Awesome Graphs for Bitbucket also gives you the capability to export commit data to CSV in different ways. As a result, you’ll get a list of commits with their details:

To export raw commit data to CSV directly from Bitbucket, you need to go to the People page. There you’ll notice the Export menu at the top-right corner, where you can choose CSV.

Another way to export commit data to CSV is to use the Awesome Graphs REST API, which allows you to automate the processes and retrieve this data easier using the dedicated resources.

You can access the in-app documentation (accessible to Awesome Graphs’ users) by choosing Export → REST API on the People page or go to our documentation website.

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"
                }
            ]
        },

Alternatively, you can use the Awesome Graphs REST API that provides global, user, project, and repository data. The solution allows you to retrieve data faster while decreasing the load on the instance compared to Bitbucket REST API. 

Use this request to get a list of commits from the specified repository.

https://example.com/rest/awesome-graphs-api/latest/projects/exampleprojectkey/repos/example-repository-slug/commits

The response will look as follows:

{
  "values": [
    {
      "user": {
        "emailAddress": "yorlov@stiltsoft.com",
        "displayName": "Administrator",
        "name": "admin"
      },
      "author": {
        "displayName": "admin",
        "emailAddress": "yorlov@stiltsoft.com"
      },
      "authorTimestamp": "2020-03-05T22:58:18Z",
      "linesOfCode": {
        "added": 1,
        "deleted": 0
      },
      "parents": [],
      "repository": {
        "slug": "Commit Hook",
        "name": "commit-hook",
        "project": {
          "key": "TESTCONTAINERS",
          "name": "Testcontainers",
          "type": "NORMAL"
        }
      },
      "id": "9f2e24a147bb8f5a5a3d10b692703cc5784df8b5"
    },
  ],
}

Learn more about the available REST API resources.

Find out what works best for you

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

  • 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 wide search opportunities and various analytical features.
  • Bitbucket REST API as a more advanced and technically demanding option.

Try them all and find the best solution!