Git 部署代码 & 打标签

修改 sshd
  • /etc/ssh/sshd_config
    PermitUserEnvironment yes
  • service sshd restart

git clone ssh://192.168.99.236/~/wanpinghui/wbs.wph.git wbs.wph.236.readonly

http://stackoverflow.com/questions/8781240/a-way-to-restrict-git-branch-access

git: who pushed in post-receive hook
http://stackoverflow.com/questions/3762012/git-who-pushed-in-post-receive-hook

  • Git Basics Tagging
  • git tag []
  • git tag -d
  • git tag
  • git tag -l
查阅指定 TAG 的时间
git show 
git log -1 --format=%ai 
git rev-parse release_20160710001021 | xargs git cat-file -p | gawk '/^author/ { print strftime(PROCINFO["strftime"], $(NF-1)) }'
  • git log --name-status --oneline --decorate | grep -e 'tag:'
    --decorate 参数会打印出所显示的 tag 名,这样才能 grep 出来;

  • 取得指定 的 author name (user.name)
    git rev-parse | xargs git cat-file -p | gawk '/^author/ { print $2 }'
    git show [] --pretty=format:%an | head -n1
    不过没什么用;

  • atlassian:jira 开发者

  • git push --tags prod-wbs +:
    将本地 连同所打 tags 一同推送到远程 prod-wbs 的
    --tags 标明将所打 tags 一同推送; refs/tags 目录下记载了所有的 tags;

  • branch,tag 都是一种 commit-ish;

  • 由于增加了推送人员的负担,故不在本地打tag,这里仅用于学习说明;

通过 ssh 找到其 comment 用于 tag name;

githooks

https://www.atlassian.com/git/tutorials/git-hooks/server-side-hooks

#!/bin/sh
# 
# lock the myfeature branch for pushing
refname="$1"

if [[ $refname == "refs/heads/myfeature" ]]
then
    echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    echo "You cannot push to myfeature! It's locked"
    echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    exit 1
fi
exit 0

设计图:
https://en.wikipedia.org/wiki/Deployment_environment

Set "denyNonFastforwards" to false

设置 denyNonFastforwards = true 更安全;在特殊情景情况下,为能强行推送,则可以设为 false;

cd example.git/
vim config
[receive]
        denyNonFastforwards = false

error: denying non-fast-forward refs/heads/master (you should pull first)

推送步骤
  • 开发在本机测试通过
  • 推送到线上
参考
  • http://stackoverflow.com/questions/2471340/is-there-a-way-to-lock-a-branch-in-git
    -http://stackoverflow.com/questions/22546393/can-git-pre-receive-hooks-evaulate-the-incoming-commit
  • http://stackoverflow.com/questions/8781240/a-way-to-restrict-git-branch-access

你可能感兴趣的:(Git 部署代码 & 打标签)