How to check the latest commit irrespective of the branch in the git history?
Asked Answered
E

3

5

In my project there are multiple branches. I want to check which is the latest commit in the history irrespective of any branch.

I have tried git log -n 1 --date-order but it gives the commit in the checked out branch

Please help me with a command that I can use to see the latest commit in the git history which is not dependent on the branch. The result should give me the commit and the branch name on which it was committed.

Endless answered 27/6, 2019 at 4:42 Comment(1)
gist.github.com/jasonrudolph/1810768 may be helpful; you'd need to trim it down to only the most recent.Protestation
D
3

This answer is based on How can I get a list of Git branches, ordered by most recent commit?, whose accepted answer sorts all branches in a Git repo by the latest commit date (i.e. the commit date of the HEAD of each branch):

git branch --sort=-committerdate

Once you find the most recently edited branch, you may simply use git log to find the SHA-1 of the HEAD commit:

git log some_branch
Dupaix answered 27/6, 2019 at 4:58 Comment(0)
G
7

You were very close. The command git log -n 1 --date-order get the last commit from the current branch. Just add --all to get commits from all branches:

git log -n 1 --date-order --all
Gymnasium answered 27/6, 2019 at 12:0 Comment(0)
D
3

This answer is based on How can I get a list of Git branches, ordered by most recent commit?, whose accepted answer sorts all branches in a Git repo by the latest commit date (i.e. the commit date of the HEAD of each branch):

git branch --sort=-committerdate

Once you find the most recently edited branch, you may simply use git log to find the SHA-1 of the HEAD commit:

git log some_branch
Dupaix answered 27/6, 2019 at 4:58 Comment(0)
C
0

For all commit irespective of branches use this command

git log --branches

Carinacarinate answered 27/6, 2019 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.