【发布时间】:2013-05-11 22:41:26
【问题描述】:
我正在创建一个脚本,该脚本将下载最新的 master 代码分支,并检查是否有任何文件名是 SQL。确定文件名后,我将获取存储过程。目前我有它拉代码并逐行准备输出,但是我的 grep 命令似乎无法找到 sql 文件名。这就是我所拥有的
#!/bin/bash
# Pull all of the latest code for the master branch, and set the commit log to
# a variable
commit_log=$(git pull origin master --quiet)
#read the commit log line by line
echo $commit_log | while read line
do
if [ `echo "$line" | grep -E "(\.sql)$"` ]; then
echo "SQL"
fi
echo "LINE:" $line
done
我没有卡在 bash 上,我也可以在 perl 中做到这一点。
【问题讨论】:
-
拉取后,运行
git diff --name-only HEAD^1..HEAD并使用那里的文件名。 -
@ScallioXTX 我要补充一点,您应该在拉取并显示您的版本和新头之间的差异之前检查您的当前版本。拉动时,您可以在一堆中收到许多提交……或者没有。任务并不是那么微不足道。如果您合并,您可能处于一个甚至不属于最终历史的修订版中。 git pull --rebase 也可能是个问题。
-
在您的构造中,括号和反引号是错误的。把它们排除在外。
-
@Lynch 好点,我的速度有点太快了。感谢您指出错误。