Finding what branch a Git commit came from

后端 未结 14 2550
失恋的感觉
失恋的感觉 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:43

    I deal with the same problem (Jenkins multibranch pipeline) - having only commit information and trying to find a branch name where this commit originally came from. It must work for remote branches, local copies are not available.

    This is what I work with:

    git rev-parse HEAD | xargs git name-rev
    

    Optionally you can strip the output:

    git rev-parse HEAD | xargs git name-rev | cut -d' ' -f2 | sed 's/remotes\/origin\///g'
    

提交回复
热议问题