Can a git-controlled file be aware of which branch it belongs to?

前端 未结 3 1097
礼貌的吻别
礼貌的吻别 2020-12-19 23:41

Maybe it might be a strange need, but I believe it would be helpful to have something like this:

if($branch$ === \"master) {
   // Special code for the maste         


        
3条回答
  •  一整个雨季
    2020-12-20 00:12

    If you need that information in hooks, the usual way is to not rely on a porcelain command, but on plumbing ones:

    #!/bin/sh
    branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
    

提交回复
热议问题