服务端CVS本地Git的版本控制:利用git钩子自定义工作流

请以解决问题为核心,不要为了用技术而用技术。

公司各个项目有CVS、SVN、HG、Git等多版本管理工具。

但CVS确实太老了,十分不便,由于历史原因公司的部分旧代码还都是用CVS来管理,恰恰是我目前在用的- -|||。但是我们可以在本地使用Git来方便代码的管理。因为Git作为分布式版本管理系统,本身local端就是完备的。

如果是用SVN、HG等版本控制系统,有git-svn等解决方案可以不改变服务端而非常方便的在本地用git,但CVS并没有找到现成的方法…,可能确实太老了吧!

最近终于想到了个方法,利用合理的流程+Git钩子,来实现Git对CVS的操作:

git push 时执行python脚本解析本次commit的文件,分别执行cvs update <filename>推送到服务器。

Git 钩子:自定义你的工作流

Git钩子是在 Git 仓库中特定事件发生时自动运行的脚本。它可以让你自定义 Git 内部的行为,在开发周期中的关键点触发自定义的行为,因为脚本可以完全定制,你可以用 Git 钩子来自动化或者优化你开发工作流中任意部分。

git钩子介绍及使用方法:https://github.com/geeeeeeeeek/git-recipes/blob/master/sources/Git%E9%92%A9%E5%AD%90.md

How To Use Git Hooks To Automate Development and Deployment Tasks: https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks

Hooks汇总:

Hook Name Invoked By Description Parameters (Number and Description)
applypatch-msg git am Can edit the commit message file and is often used to verify or actively format a patch‘s message to a project‘s standards. A non-zero exit status aborts the commit. (1) name of the file containing the proposed commit message
pre-applypatch git am This is actually called after the patch is applied, but before the changes are committed. Exiting with a non-zero status will leave the changes in an uncommitted state. Can be used to check the state of the tree before actually committing the changes. (none)
post-applypatch git am This hook is run after the patch is applied and committed. Because of this, it cannot abort the process, and is mainly used for creating notifications. (none)
pre-commit git commit This hook is called before obtaining the proposed commit message. Exiting with anything other than zero will abort the commit. It is used to check the commit itself (rather than the message). (none)
prepare-commit-msg git commit Called after receiving the default commit message, just prior to firing up the commit message editor. A non-zero exit aborts the commit. This is used to edit the message in a way that cannot be suppressed. (1 to 3) Name of the file with the commit message, the source of the commit message (messagetemplatemergesquash, or commit), and the commit SHA-1 (when operating on an existing commit).
commit-msg git commit Can be used to adjust the message after it has been edited in order to ensure conformity to a standard or to reject based on any criteria. It can abort the commit if it exits with a non-zero value. (1) The file that holds the proposed message.
post-commit git commit Called after the actual commit is made. Because of this, it cannot disrupt the commit. It is mainly used to allow notifications. (none)
pre-rebase git rebase Called when rebasing a branch. Mainly used to halt the rebase if it is not desirable. (1 or 2) The upstream from where it was forked, the branch being rebased (not set when rebasing current)
post-checkout git checkoutand git clone Run when a checkout is called after updating the worktree or after git clone. It is mainly used to verify conditions, display differences, and configure the environment if necessary. (3) Ref of the previous HEAD, ref of the new HEAD, flag indicating whether it was a branch checkout (1) or a file checkout (0)
post-merge git merge or git pull Called after a merge. Because of this, it cannot abort a merge. Can be used to save or apply permissions or other kinds of data that git does not handle. (1) Flag indicating whether the merge was a squash.
pre-push git push Called prior to a push to a remote. In addition to the parameters, additional information, separated by a space is passed in through stdin in the form of "<local ref> <local sha1> <remote ref> <remote sha1>". Parsing the input can get you additional information that you can use to check. For instance, if the local sha1 is 40 zeros long, the push is a delete and if the remote sha1 is 40 zeros, it is a new branch. This can be used to do many comparisons of the pushed ref to what is currently there. A non-zero exit status aborts the push. (2) Name of the destination remote, location of the destination remote
pre-receive git-receive-pack on the remote repo This is called on the remote repo just before updating the pushed refs. A non-zero status will abort the process. Although it receives no parameters, it is passed a string through stdin in the form of "<old-value> <new-value> <ref-name>" for each ref. (none)
update git-receive-pack on the remote repo This is run on the remote repo once for each ref being pushed instead of once for each push. A non-zero status will abort the process. This can be used to make sure all commits are only fast-forward, for instance. (3) The name of the ref being updated, the old object name, the new object name
post-receive git-receive-pack on the remote repo This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of "<old-value> <new-value> <ref-name>". Because it is called after the updates, it cannot abort the process. (none)
post-update git-receive-pack on the remote repo This is run only once after all of the refs have been pushed. It is similar to the post-receive hook in that regard, but does not receive the old or new values. It is used mostly to implement notifications for the pushed refs. (?) A parameter for each of the pushed refs containing its name
pre-auto-gc git gc --auto Is used to do some checks before automatically cleaning repos. (none)
post-rewrite git commit --amendgit-rebase This is called when git commands are rewriting already committed data. In addition to the parameters, it receives strings in stdin in the form of "<old-sha1> <new-sha1>". (1) Name of the command that invoked it (amend or rebase)

Workflow for Remote CVS, Local Git

所有命令在Git Bash中执行,和正常的git流程相比:

1、git pull 被 cvs update 替换,且最好只在master上进行。

2、每次update后需要git commit -a "syn cvs date+msg" 执行一次commit,把本次cvs更新的内容加入git版本库。

其他完全一样,随意切换分支!记得git stash save !

其他注意项:

1、在本地CVS代码处初始化git库

2、填写.gitignore规则,先commit,在 git bash 中 cvs update 后整体commit作为初始版本。

3、git master分支和远端cvs master分支对应,此后master分支只处理合入,dev分支最为常用开发。

4、设置一个有效的git remote url,才能执行git push利用Hook: pre-push,使用sys.exit(1)放弃本次git push。

时间: 2024-08-24 18:35:21

服务端CVS本地Git的版本控制:利用git钩子自定义工作流的相关文章

Git入门:安装环境 版本回退 仓库实战 搭建git服务端

备份MBR:dd  if=/dev/sda of=/data/mbr.dump bs=512 count=1 恢复MBR:dd  if=/data/mbr.dump of=/dev/sda bs=446 count=1      --- 小 Q --------------------------------------------------------------------------------------------------- Git:Linus开发分布式版本控制系统,和Linux

使用Zabbix服务端本地邮箱账号发送报警邮件的部署记录

邮件报警有两种情况:1)Zabbix服务端只是单纯的发送报警邮件到指定邮箱,发送报警邮件的这个邮箱账号是Zabbix服务端的本地邮箱账号(例如:[email protected]),只能发送,不能接收外部邮件.2)使用一个可以在互联网上正常收发邮件的邮箱账号(例如:[email protected]),通过在Zabbix服务端中设置,使其能够发送报警邮件到指定邮箱.上面第2中使用外部邮箱发送报警邮件之前已经介绍了:分布式监控系统Zabbix-3.0.3-完整安装记录(5)-邮件报警部署.下面说下

git服务器搭建post-receive 钩子部署服务端代码

一.git服务器搭建(服务器用户:root) 安装git $ apt-get install git 创建git用户 $ adduser git$ passwd git //修改git用户密码 创建git仓库 $ cd /home$ mkdir git$ mkdir ./git/.ssh$ touch./git/.ssh/authorized_keys$ cd /home/git$ git init --bare test.git //初始化仓库$ chown -R git:git ../git

java实现服务端守护进程来监听客户端通过上传json文件写数据到hbase中

1.项目介绍: 由于大数据部门涉及到其他部门将数据传到数据中心,大部分公司采用的方式是用json文件的方式传输,因此就需要编写服务端和客户端的小程序了.而我主要实现服务端的代码,也有相应的客户端的测试代码.这里须有一个需要提到的是,我在实现接收json文件的同时,而且还需将数据写到hbase中.写入到hbase当中采用的是批量插入的方式,即一次插入多条记录. 好了,有了前面的说明,下面来简单的说一下我实现的服务端的小程序把. 2.为了实现服务端能够监听客户端的行为,因此我在服务端采用多线程的技术

版本控制使用git比svn更有优势

Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多的影响,文章分为两部分,第一部分介绍Git的一些常用命令,其中穿插介绍Git的基本概念和原理,第二篇重点介绍 Git的使用技巧,最后会在Git Hub上创建一个开源项目开启你的Git实战之旅 1.Git是什么 Git在Wikipedia上的定义:它是一个免费的.分布式的版本控制工具,或是一个强调了速度快的源代码管理工具.G

Android中直播视频技术探究之---视频直播服务端环境搭建(Nginx+RTMP)

一.前言 前面介绍了Android中视频直播中的一个重要类ByteBuffer,不了解的同学可以 点击查看 到这里开始,我们开始动手开发了,因为我们后续肯定是需要直播视频功能,然后把视频推流到服务端,本地在进行拉流播放的流程.所以这个过程中,我们需要首先来把服务端这个中间环节的工作搞定,后续再弄推流和拉流功能.现在推流大部分都是使用RTMP/HLS协议的,关于这两个协议的区别: 所以我们服务端搭建就需要用这两个协议,不过本文放心了,不会去手动的编写一套协议代码的,谁叫这个世界属于开源呢? 需要的

文件下载之断点续传(客户端与服务端的实现)

原文:http://www.cnblogs.com/zhaopei/p/download.html 阅读目录 文件下载-服务端 使用a标签提供文件下载 使用Response.TransmitFile提供文件下载 其他方式文件下载 文件下载-客户端 直接下载 异步下载 断点续传 断点续传(服务端的支持) 多线程同时下载(分片下载) 前面讲了文件的上传,今天来聊聊文件的下载. 老规矩,还是从最简单粗暴的开始.那么多简单算简单?多粗暴算粗暴?我告诉你可以不写一句代码,你信吗?直接把一个文件往IIS服务

Git TortoiseGit 版本控制【总结】

Git   TortoiseGit 版本控制工具 Git 的安装 下载:https://git-for-windows.github.io/ 或 https://git-scm.com/ 除了安装路径,全部按默认即可: --> 选择安装路径 --> 使用默认的组件 --> 创建开始菜单文件夹 --> 选择使用Git的命令行模式,选择默认Git Bash模式会创建一个快捷命令行: --> 选择换行格式,默认为第一个跨平台样式: --> Finish 安装完成,桌面会生成一

【转】文件下载之断点续传(客户端与服务端的实现)

[转]文件下载之断点续传(客户端与服务端的实现) [转]文件下载之断点续传(客户端与服务端的实现) 前面讲了文件的上传,今天来聊聊文件的下载. 老规矩,还是从最简单粗暴的开始.那么多简单算简单?多粗暴算粗暴?我告诉你可以不写一句代码,你信吗?直接把一个文件往IIS服务器上一扔,就支持下载.还TM么可以断点续传(IIS服务端默认支持). 在贴代码之前先来了解下什么是断点续传(这里说的是下载断点续传)?怎么实现的断点续传?断点续传就是下载了一半断网或者暂停了,然后可以接着下载.不用从头开始下载. 很