Git Post Merge Hook无法识别有效命令

时间:2015-08-26 07:15:15

标签: git bash

这是我的合并后钩子脚本。尝试基于currentBranch在后合并上进行一些清理/设置。没有得到我期望的输出

# !/bin/bash 

git branch --contains $2
curbranch1=$(git branch --contains $2)
echo  $curbranch1
curbranch2=$(echo "$curbranch1"|grep "*")
echo  $curbranch2


#output

Switched to branch 'develop'
* develop
NET SRC-Fiery-PF-PS VB6Dev bin develop
NET SRC-Fiery-PF-PS VB6Dev bin develop

1 个答案:

答案 0 :(得分:2)

尝试为等号周围没有空格的变量赋值:

currentBranch=$(git branch --contains $2)
  

NET SRC-Fiery-PF-PS VB6Dev bin develop <--Should match previous line?

这意味着默认情况下不会保留换行符 分两步尝试:

currentBranch=$(git branch --contains $2)
currentBranch=$(echo "$currentBranch"|grep "*")

另见&#34; How can I have a newline in a string in sh?&#34;

即使只是一步,它也可以:

#!/bin/sh

n=$(git branch --contains @|grep "*")
echo "$n"