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