2

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.

Y-B Cause
  • 1,101
  • 12
  • 35
  • Possible duplicate of [How can I get a list of git branches, ordered by most recent commit?](https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit) – Tim Biegeleisen Jun 15 '17 at 04:15
  • @TimBiegeleisen I just had a look at it. They look alike but I only need the id, not the other information. I'll edit the post if I manage to do it using `git for-each-ref --sort=-committerdate refs/heads/` as the answers of the post suggest. – Y-B Cause Jun 15 '17 at 04:22

1 Answers1

2

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.

Y-B Cause
  • 1,101
  • 12
  • 35