Rakmo
Rakmo

Reputation: 1982

How to get commit hash in git show-branch?

git show-branch branchX branchY

Output Format:

+  [branchX~1] Commit Message Here

This shows the relative count from the tip commit of branchX. Is there any way to include the corresponding commit hash (short or long) too? I referred the docs but was unable to find anything.

PS: I have many commits on the output list, so I don't prefer to check in logs one by one.

Upvotes: 2

Views: 1252

Answers (2)

Rakmo
Rakmo

Reputation: 1982

Found it in the docs link itself which has been mentioned.

--sha1-name does the trick.

Sol:

git show-branch --sha1-name branchX branchY

Output:

+  [COMMIT-HASH] Commit Message Here

Upvotes: 4

Romain Valeri
Romain Valeri

Reputation: 21918

You can use git for-each-ref and benefit from its formatting options, like this

git for-each-ref --format="[%(refname:short) %(upstream:track)] %(objectname:short) %(contents)" refs/heads/<branchName>

Example output :

[master [ahead 1]] e1c8aad Commit message here

This is for one branch <branchName>, but for the branches list in this format, just replace refs/heads/<branchName> with refs/heads/

Upvotes: 3

Related Questions