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.
Asked
Active
Viewed 733 times
3 Answers
5
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

Vandesh
- 6,368
- 1
- 26
- 38
-
1Yes for `branch --contains`. I was in the process of writing a similar answer. This is the way to go. – Romain Valeri Sep 18 '19 at 14:11
-
It's correct answer but this command works only in bash shell. – xrayx Sep 18 '19 at 14:20
-
@Rav3 True. For any other means, you'd need to use the way for that particular medium to be able to pass the output of one command to the other – Vandesh Sep 18 '19 at 14:22
-
@Vandesh in my case I used WSL. – xrayx Sep 18 '19 at 14:24
0

ANIK ISLAM SHOJIB
- 3,002
- 1
- 27
- 36
-
It doesn't work. I am running this command in one of my branch directory and I've got only one commit. – xrayx Sep 18 '19 at 13:55
-
see my image works for me maybe something else going on in your branch – ANIK ISLAM SHOJIB Sep 18 '19 at 14:00
0
git rev-list --all | grep <your-partial-sha1>
... will output all of the commits from your repository whose SHA-1 matches.

Quentin
- 62,093
- 7
- 131
- 191