我想在提交的任何时候将提交哈希的前几个字符和提交消息自动插入到gh-pages
分支中的文件中master
。
目前使用这个post-commit
钩子:
#!/bin/bash
#Ensures we are in master branch
[ `git rev-parse --abbrev-ref HEAD` != "master" ] && exit 1
git checkout gh-pages
git merge master
# update the js file with commit identification information from git
# I can't seem to get this to work without generating a *_bak file. Whatever.
# I have a section in my source that has delimiters #% %# that I use to stuff the
# git commit into, so I can view the version of source I am testing on my device
# very easily (you can't imagine how much more definite and efficient this is compared
# to what we do at my work)
sed -i _bak "s/#%.*%#/#% `git log master -1 --format="%h %s"` %#/" source.js
git commit -a -m"this commit made by a script"
git checkout master
我怀疑将其转换为commit-msg
钩子可以让我减少生成的额外提交的数量(两个,一个将 master 合并到 gh-pages 中,一个将我用于 master 提交的 commit-msg 写入文件)每当我在 上执行提交时master
,它至少可以让我通过执行commit -n
for轻松跳过它--no-verify
,而使用post-commit
钩子我必须取消设置钩子文件上的 exec 标志以暂时禁用它。
这行得通吗?我想我应该试试看。不过,Git 会做什么呢?只要我的 bash 脚本发出 0 的返回值,它就会继续执行提交?