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

前端 未结 3 1117
礼貌的吻别
礼貌的吻别 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:11

    No, all meta file information is stored under .git in the root directory. You can detect the current branch with the following bash command (code modified, but originally found here):

    function parse_git_branch() {
      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
    }
    

提交回复
热议问题