Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,659
Community Members
 
Community Events
185
Community Groups

How to find the latest commit made on a branch?

I'm trying to extract the last commit made to a certain branch.

 

I have something like this here:

https://stash.mycompany.com/rest/branch-utils/1.0/projects/{abcd}/repos/{abcde-fghi}/branches/info/{CommitID} but what I do not get in this request is the time the last commit was made to this branch.

Is there a way to achieve that?

3 answers

I get from calling this using curl :

curl -u <bitbucket_username>:<app_password>  https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/commits/master | python3 -c "import json,sys;obj=json.load(sys.stdin);print(obj['values'][0]['hash']);


 

It will directly give you the commit_no. 

0 votes
Julius Davies _bit-booster_com_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 15, 2017

If you need to get latest commit on a branch through the REST api, try the "/commits" call with the "until" parameter set to the branch you are interested in, and limit=1 to get the single tip commit from the branch.

Example:

http://vm.bit-booster.com/bitbucket/rest/api/1.0/projects/BB/repos/aui/commits?until=master&limit=1

 

The "authorTimestamp" in the result will tell you when the commit was first created.

If you're on Bitbucket 5.0 or newer, then a "committerTimestamp" should be present as well.   If an original commit was rebased or cherry-picked or squashed, the "committerTimestamp" will tell you when those operations happened.

The actual "push" time for when the commit arrived at the server is much harder to determine.

0 votes
somethingblue
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Aug 15, 2017

Hi Vivek,

You can use the following to get the last commit:

git log -1 

To just get the date you can do the following:

git log -1 --format=%cd 

Cheers,

Branden

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events