1
之前应用我编写了一个预提交挂钩来增加源中的版本号。为什么在提交后应用更改?在提交之前我该怎么做?git预提交代码修改在提交之后应用,而不是在
#!/bin/sh
# Hook to increment version number before checkin
REPO_DIR=$(cd `dirname $0`/../.. && pwd)
VERS_FILE="${REPO_DIR}/version.php"
CUR_DATE=`date -u '+%Y-%m-%d %H:%M:%S'`
HOOK=`basename $0`
if [ -w ${VERS_FILE} ]; then
# increment last digit of version string
perl -i -pe 's/(\$version\s?=\s?['\''|"][\d\.]+)(\d+)/"$1".($2+1)/e' "${VERS_FILE}"
RV=$?
if [ 0 -ne ${RV} ]; then
echo "ERROR: Updating version in ${VERS_FILE} failed"
exit $RV
fi
echo "INFO: Increment version in file ${VERS_FILE}"
fi
echo "Finish $HOOK at $CUR_DATE"
exit 0
我知道这种自动更改不建议。但从技术上讲,这应该是可能的。我在Ubuntu 9.10上使用git 1.6.3.3。
感谢您的帮助。我在脚本的末尾添加了命令'git add -u - “$ {VERS_FILE}”''',它起作用。但请注意,提交消息不会将该文件显示为已修改。 – StackUnderflow