Reputation: 120
In GitKraken, we report from one branch to another commits with the same reference.
Problem : It's difficult to detect in which branch the commit is located if we do a search with CTRL+F.
Is there a way to know the name of the branch from a commit?
We have 7 commits with the same reference
If I select one of them, I'm positioned on a commit. From this view, it is impossible for me to know the name of the branch.
Upvotes: 3
Views: 2249
Reputation: 11338
I am definitely the less knowledgeable in git from all of you here, but what about:
git show [commit-hash]
in a git bashThe info displayed at origin/version-210627 seems to show the branch (version-210627 in my case).
Upvotes: -1
Reputation: 1539
Try this :
git branch --contains <commit>
And read this: How to list branches that contain a given commit?
Upvotes: 9
Reputation: 794
You can find it if you know the commit id. Use "ctrl+f" and it will open "Search Commits" dialog where you need to enter commit id. After you press enter, the tree graph will navigate to that commit and you can see visually on which branch it is placed.
Upvotes: 1
Reputation: 14439
In short: No.
As @RomainValeri said in his comment: a commit does not "belong" to any branch. A branch is nothing more than a pointer to a commit. There may be a hundred branches from which a commit is reachable, or there may be none.
The git command git branch --contains <commit>
, suggested by @MohammadAnsari, will show you a list of all branches from which the commit is reachable.
As to GitKraken: There is no immediate solution for your problem. If the commit is further down the graph, it's hard to tell to which strain of ancestor commits it leads. Also, there is no GitKraken command that does what git branch --contains <commit>
does (or none I know of).
Maybe you should overthink your wokflow of having commits with the same name, or rethink your branching strategy. Do you have several long running branches? If all branches would converge against a single master
, the question would be trivial.
Upvotes: 1
Reputation: 30858
For a commit $commit
, to find the branches that exactly point at it:
git for-each-ref refs/heads --format="%(refname:lstrip=2)" --points-at $commit
And to find the branches from which it is reachable:
git for-each-ref refs/heads --format="%(refname:lstrip=2)" --contains $commit
Upvotes: 2