2975

git远程仓库,同步钩子、回撤等相关操作

乐果   发表于   2015 年 08 月 07 日 标签:git

一、首先安装一个git管理软件,例如golang开发的gogs挺不错的。

二、配置hooks(post-receive)

1、进入git的仓库配置目录,找到hooks目录进入,添加post-receive文件,编辑如下:

#!/bin/sh
unset GIT_DIR
NowPath=`pwd`
echo "now path is :"$NowPath
DeployPath="/data/src/sscmp/"
WebPath="/data/www-data/sscmp/"
echo "deploy path is :"$DeployPath
cd $DeployPath
echo "cd deploy path"
git fetch origin
git pull
echo "deploy done"
cd $NowPath
echo "pull fine"
# --- Finished

rsync -aH --delete --progress --exclude=".git/" $DeployPath $WebPath >/dev/null
echo "rsync fine"

chmod -R 777 $WebPath

exit 0

三、git远端仓库回退版本操作

git log 命令查看提交的版本日志

git reset --hard xxxxxxxxxxxxxxxxxxxxxxx 将本地仓库版本回撤到指定版本

git push --force origin master 将本地回撤后到版本,强行推送到远程仓库覆盖。

注意:这个--force就是 强行覆盖 ,非特殊情况千万别使用,不然会导致远程仓库其他同事提交的代码被覆盖,正常情况下若远程仓库版本比你本地仓库版本新,push时会提示要先pull,pull若有提示冲突,应该在本地解决冲突后再push。

git reflog 可以查看回撤等历史操作记录,若不当回撤后,可以再次还原。。。

乐果   发表于   2015 年 08 月 07 日 标签:git

0

文章评论