xrayx
xrayx

Reputation: 65

How to find commit in all branches based on part of id

How can I find commit in all branches? In my case it is more than 20 branches and I've only part of commit id. I know only that it is part of begin or end commits id. All branches excludes one are remote.

Upvotes: 5

Views: 1097

Answers (3)

Vandesh
Vandesh

Reputation: 6904

I think what you're looking for is a combination --contains option with finding a commit from the revision list using rev-list

git branch -a --contains $(git rev-list --all | grep <your-partial-commit-id>)

It finds first the full commit id using the partial with

git rev-list --all | grep <your-partial-commit-id>

And then you pass the full commit id to search in all the branches using the -a option (for all branches), with the commit id passed to the --contains argument

git branch -a --contains <your-full-commit-id>

Additional Note: In your case, this is not true, but if it is known that the partial id is the beginning part of the full commit id (any length), then you can just directly pass it to git branch --contains without getting the full id from the rev-list command

Upvotes: 6

ANIK ISLAM SHOJIB
ANIK ISLAM SHOJIB

Reputation: 3258

this command will save your life

git reflog

reference here

enter image description here

Upvotes: 0

Quentin
Quentin

Reputation: 63154

git rev-list --all | grep <your-partial-sha1>

... will output all of the commits from your repository whose SHA-1 matches.

Upvotes: 0

Related Questions