版本控制软件、代码托管、SmartGit

以前写了一些代码,现在找起来有些困难。于是花了些时间,较为系统了解了下版本控制软件及其相关内容,重点介绍Git和Mercurial版本控制软件的代码托管网站、常用命令、图形化工具。最后介绍SmartGit在Ubuntu和Windows上的安装。

1. 版本控制

1.1 版本控制软件

版本控制软件(revision control software)提供完备的版本管理功能,用于存储、追踪目录(文件夹)和文件的修改历史,其目标是支持软件公司的配置管理活动,追踪多个版本的开发和维护活动,及时发布软件[1]

目前,已有很多版本控制软件,详情可查阅维基词条:List of revision control software。常见的有:

  • Concurrent Versions System (CVS) – originally built on RCS, licensed under the GPL. 基于客户端/服务器结构,将一组文件放在层次目录树中以保持同步的系统。已被SVN、Git取代
  • Subversion (SVN) – versioning control system inspired by CVS. 设计目标是取代CVS,采用了分支管理系统。有不少客户端图形化软件,研究生期间的项目组用的就是TortoiseSVN
  • Git – written in a collection of Perl, C, and various shell scripts, designed by Linus Torvalds based on the needs of the Linux kernel project; decentralized, and aims to be fast, flexible, and robust. 支持Git的源码访问服务有GitHub, Google Code, SourceForge等。GitHub是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目
  • Mercurial – written in Python as an Open Source replacement to BitKeeper; decentralized and aims to be fast, lightweight, portable, and easy to use. 对Mercurial的所有操作都由“hg”加上不同的关键字作为参数来完成

从平时安装软件来看,Git和Mercurial用得最多,感觉Mercurial更高端一些,也许得益于Python的易用性。

1.2 代码托管

上述介绍的是版本管理软件,可以把代码放在自己的服务器上,也可以放在专业的托管商那,就好比如博客可以放在自己的服务器上或者虚拟服务器上,也可以放在诸如新浪博客的托管商上。接下来介绍Git和Mercurial的一些托管网站。

(1)Git

Git代码托管网站为GitHubGitHub是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目。话说,还有其他Git代码托管网站吗?

(2)Mercurial

提供免费的Mercurial版本库托管的网站有:SourceForge, Google Code,详细列表可查看《Mercurial Hosting》   

1.3 常用命令

1.3.1 Git

Git使用指南:http://git-scm.com/docs/user-manual

(1)通过Git下载软件

在GitHub找到相关的软件下载,举例如下

git clone https://github.com/SparkandShine/save_restore_term_config.git

(2)配置GitHub[6]

#step 1: 安装git
sudo apt-get install git-core

#step 2: 申请GitHub账户
上github.com申请账户

#step 3: 在本地建立一个文件夹,做一些全局变量的初始化
git config --global user.name = "用户名或者用户ID"
git config --global user.email = 邮箱
         
#step 4: 创建验证用的公钥
#git是通过ssh的方式访问资源库的,所以需要在本地创建验证用的文件。
ssh-keygen -C 'you email address@gmail.com' -t #rsa会在用户目录~/.ssh/下建立相应的密钥文件
ssh -v git@github.com #测试链接是否畅通

#step 5: 上传公钥
#登入github.com --> 右上角Settings -->  SSH Keys --> Add SSH Key
Title可以随便命名
Key的内容拷贝自~/.ssh/id_rsa.pub中的内容

ssh -v git@github.com #测试链接是否畅通

(3)用GitHub管理项目[6]

利用github管理项目,操作步骤如下:

### Git配置与使用
#step 1: 建立仓库
git init #在需要建立项目的文件夹中,完成后,可以看到文件夹中多了一个.git隐藏目录

#step 2: 添加文件
git add .  #这里.表示文件夹下的所有文件,也可以指定文件进行添加

#step 3: 提交文件
git commit  -m 'first comment' #对编辑的内容进行提交

#step 4: 删除或增加github远程来源
git remote add origin https://github.com/SparkandShine/save_restore_term_config.git #网址为github托管的仓库地址

#step 5: 提交至github仓库
git push origin master

1.3.2 Mercurial

Clone a project and push changes

$ hg clone http://selenic.com/repo/hello
$ cd hello
$ (edit files)
$ hg add (new files)
$ hg commit -m 'My changes'
$ hg push

Create a project and commit

$ hg init (project-directory)
$ cd (project-directory)
$ (add some files)
$ hg add
$ hg commit -m 'Initial commit'

1.4 图形化界面

可以用Git和Mercurial提供的命令进行所有操作,前者以git开头,后者以hg开头。图形化界面

1.4.1 Git

支持Git的图形化工具可查阅官方文档《Interfaces, frontends, and tools》。主要工具如下:

  • git-cola (GitHub, homepage, gitweb) by David Aguilar is an advanced Git commit tool, similar to git-gui, written in PyQt4. git-cola features a graphical 2D history viewer, easy, interactive partial-diff staging, inotify support, and more. You can get tarballs at http://cola.tuxfamily.org/. Native packages exist for Debian, Fedora, and Arch. Mac OSX and Windows builds are available on the website.
  • gitg (gitg) by Jesse van den Kieboom is a clone of GitX for gtk+/GNOME. As such it tries to follow the implementation of GitX closely, while providing tight integration into the GNOME desktop.
  • SmartGit by Syntevo GmbH is a graphical Git client which runs on all major platforms (e.g. Linux, Mac OS X, Microsoft Windows). It requires (SUN-) Java 1.5 or newer as well as a Git installation. Closed source, free of charge for non-commercial usage.
  • git-gui (announcement, gitweb) by Shawn Pearce is a tool for creating commits and managing branches. It was inspired by and initially based on gitool. Written in Tcl/Tk. Stable versions are shipped with Core Git since version 1.5.
  • TortoiseGit

1.4.2 Mercurial

支持Mercurial的图形化工具可查阅官方文档《Other Tools》,主要有:

  • TortoiseHg – OS-level Mercurial integration on Windows (similar to TortoiseSVN), Linux (stand-alone or with Nautilus integration)
  • gquilt – A PyGTK-based wrapper for quilt and mq
  • gwsmhg – A PyGTK-based work space manager using hg and mq
  • HgWin – A GUI-based tool similar to hgtk (requires .NET Framework v3.5 SP1 or higher)
  • EasyMercurial – A simple, user-friendly cross-platform client, originally based on HgExplorer, designed with new users and straightforward setups in mind
  • hgtui – A TUI-based tool written in Python
  • SmartGit/Hg – A solid cross-platform client for Mercurial, Git and SVN (free for non-commercial use)

经过简单了解,最后决定选择SmartGit,理由是跨平台,而且也被推荐得比较多。

2. SmartGit安装

2.1 Ubuntu

从官方网站下载http://www.syntevo.com/smartgit/, 解压tar -xvf smartgit-generic-6_5_2.tar.gz,进入bin目录,运行命令:

smartgit/bin$ ./smartgit.sh

2.2 Windows

从官方网站下载http://www.syntevo.com/smartgit/,按提示安装。 安装完后,打开SmartGit,在Repository –> Clone对话框做如下操作,这样就可以将GitHub上的文件同步到本地。在菜单栏选择View —> Show Unchanged File,就可以看到全部文件了。

image

对文件修改后,点击工具栏的commit->commit&push,就可以同步到GitHub了。

参考资料:
[1]百科词条:版本控制软件
[2]维基百科:开源软件托管软件
[3]StackOverflow:Git GUI client for Linux
[4]6 Useful Graphical Git Client for Linux
[5]List of revision control software
[6]博文《Ubuntu下Git安装与使用

专题: 代码版本控制 (1/2)

赞赏

微信赞赏支付宝赞赏

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

2 thoughts on “版本控制软件、代码托管、SmartGit