我也試圖做到這一點。但是,我似乎無法從@shelhamer獲得解決方案以在我的代碼庫中工作。下面是得到它的工作更新的post-commit鉤子,我用的腳本:
#!/bin/sh
WATCH_BRANCH="master"
WATCH_FILES="jquery-imask-min.js"
DEST_BRANCH="gh-pages"
# bail out if this commit wasn't made in the watched branch
THIS_BRANCH=$(git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/');
if [ "$THIS_BRANCH" != "$WATCH_BRANCH" ]; then
exit 0
fi
# only update if watched files have changed in the latest commit
CHANGED_FILES=$(git show --pretty="format:" --name-only $WATCH_BRANCH)
if $(echo "$CHANGED_FILES" | grep "^$WATCH_FILES$" -q); then
# checkout destination branch, then
# checkout latest version of each watched file and add to index
git checkout -q $DEST_BRANCH
git pull -q
SAVEIFS=$IFS
IFS=$(echo -n "|")
for file in $WATCH_FILES; do
git checkout $WATCH_BRANCH -- $file
git add $file > /dev/null
done
IFS=$SAVEIFS
# commit with a chance to edit the message, then go back to watched branch
LATEST_COMMIT=$(git rev-parse $WATCH_BRANCH)
git commit -m "Also including changes from $WATCH_BRANCH's $LATEST_COMMIT"
git push origin $DEST_BRANCH
git checkout -q $WATCH_BRANCH
fi
我不得不更新使用grep來使正則表達式匹配成功(-P是不是對的grep執行的選項中包括在Windows的Git Bash shell中),添加一個git pull
和一個git push origin $DEST_BRANCH
。噢,我必須事先添加一個空目錄和文件的shell(也許只是目錄已經足夠了?)。
因爲這實際上是在推送,所以我認爲最好將這個腳本切換爲post-receive腳本而不是post-commit。否則,你可能會推動代碼到gh頁面,從來沒有成爲主人[如果你選擇不推動它]。
是的,這樣做的問題是,每次我提交一個提交給master切換到分支和複製文件的頁面時,它都需要額外的工作。我只是試圖避免這個,因爲它似乎沒有必要 –