How can I run git log between two branches?

I want to log the differences between two branches. On git I can do this with:

git log -1 origin/mybranch ^origin/trunk

Is there any way of doing this on Bitbucket Server?

Hi @tom.isaacson,
Have you looked at the CommitsBetweenRequest?

It can be fed to the CommitService#getCommitsBetween method to produce that output.

Cheers
Juan

1 Like

I should have been more specific -is there any way of doing that through the API? It looks like I’d have to write a plugin to use that function.

Hi @tom.isaacson,

From this:

It’s a simple way to show the differences between 2 branches. Consider the following command:

git log master..feature

The master…feature range contains all of the commits that are in the feature branch, but aren’t in the master branch. In other words, this is how far feature has progressed since it forked off of master.

Or via UI: https://bitbucket.org/site/master/issues/9257/view-diff-between-branches

Hope that helps.

Cheers,
Anne Calantog

I’m not sure what you’re suggesting here? I know what git log does. But it only works if you’re in the git repository. What I’m trying to do is write a Python app that can run this command without being in a repo. It seems like CommitsBetweenRequest is an internal command.

HI @tom.isaacson,

Ah. I thought you needed a command cause you mentioned that you needed to write a plugin to use the CommitsBetweenRequest. Apologies for the confusion.

Cheers,
Anne Calantog

Hi @tom.isaacson,

I’m assuming you would like to do this through the REST API, since the previous comment giving you the Java API wasn’t helpful.
There is a REST endpoint you can get this from: https://docs.atlassian.com/bitbucket-server/rest/5.10.1/bitbucket-rest.html#idm45736094257136

You’ll want to include the since and until query params as the two branches you want to diff between, so you will do a GET on something like this:

https://{path-to-bitbucket}/rest/api/latest/projects/{projectKey}/repos/{repoSlug}/commits?since={from_branch}&until={to_branch}

This is the same endpoint that the javascript hits on the compare page, so if you looked at the network traffic on that page, you would see the endpoint in action.

Hope this helps!
Kristy