Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

Is there any way to find out what branch a commit comes from given its sha1?

Bonus points if you can tell me how to accomplish this using Ruby Grit.

1 Answer

0 votes
by (27.5k points)

This command should do the magic:

$ git name-rev <SHA>

For example: 

Branch name: new-branch

$ git name-rev 651ad3a251ad3a remotes/origin/new-branch

Even this is working for complex scenarios like:

origin/branchA/

              /branchB

                      /commit<SHA1>

                                   /commit<SHA2>

Here, git name-rev commit<SHA2> returns branchB

Related questions

Browse Categories

...