Zoette
Zoette

Reputation: 1291

Get the id of the last git commit on any branch

I'm currently using git rev-parse origin/master to retrieve the id of the last commit on master branch. But I would like to get the very last commit on any branch of the project. Is there a way to achieve this? Thank you.

EDIT: I found the way of retrieving the last commits IDs:

git for-each-ref --sort=-committerdate refs/heads/ --format='%(objectname)'

But I would like to retrieve only the very last ID instead of the whole list.

Upvotes: 2

Views: 95

Answers (1)

Zoette
Zoette

Reputation: 1291

Alright, I finally did it.

git for-each-ref --sort=-committerdate refs/heads/ --format='%(objectname)' --count=1

The output is the sha of the very last commit on any branch of the project.

Upvotes: 2

Related Questions