Finding what branch a Git commit came from

后端 未结 14 2632
失恋的感觉
失恋的感觉 2020-11-22 10:43

Is there a way to find out what branch a commit comes from given its SHA-1 hash value?

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

14条回答
  •  鱼传尺愫
    2020-11-22 11:36

    This simple command works like a charm:

    git name-rev

    For example (where test-branch is the branch name):

    git name-rev 651ad3a
    251ad3a remotes/origin/test-branch
    

    Even this is working for complex scenarios, like:

    origin/branchA/
                  /branchB
                          /commit
                                       /commit
    

    Here git name-rev commit returns branchB.

提交回复
热议问题