公司版本控制用的是hg,总结了下自己在使用过程中的经验。
l Ubuntu 下安装TortoiseHG
1、加入ppa:mercurial
2、加入ppa:TortoiseHG
3、update apt
4、install TortoiseHG
5、重启系统
6、OK了
@ubuntu:~$ sudo add-apt-repository ppa:tortoisehg-ppa/releases
@ubuntu:~$ sudo apt-get update
@ubuntu:~$ sudo apt-get install tortoisehg
@ubuntu:~$ sudo add-apt-repository ppa:mercurial-ppa/releases
@ubuntu:~$ sudo apt-get update
@ubuntu:~$ sudo apt-get install tortoisehg
参考部分:
http://www.cnblogs.com/khler/archive/2010/08/27/1810365.html
http://www.cnblogs.com/cute/archive/2012/05/21/2511571.html
l 生成ssh的密钥
在linux系统中,ssh是远程登录的默认工具,因为该工具的协议使用了RSA/DSA的加密算法.该工具做linux系统的远程管理是非常安全的。telnet,因为其不安全性,在linux系统中被搁置使用了。
ssh有一套很有用的工具,其中的ssh-keygen可以用来生成private和public密钥.将生成的public密钥拷贝到远程机器后,可以使ssh到另外一台机器的登陆不用密码.具体方法如下.
1. 生成密钥
在本地机器中的~/.ssh/目录下执行下命令,
ssh-keygen -t dsa
将生成两个文件,id_dsa和id_dsa.pub.
2. 设置权限
To fix this, you'll need to reset the permissions back to default:
sudo chmod 600 ~/.ssh/id_dsa
sudo chmod 600 ~/.ssh/id_dsa.pub
If you are getting another error:
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/geek/.ssh/known_hosts).
This means that the permissions on that file are also set incorrectly, and can be adjusted with this:
sudo chmod 644 ~/.ssh/known_hosts
Finally, you may need to adjust the directory permissions as well:
sudo chmod 755 ~/.ssh
This should get you back up and running.
把生成的公钥给leader。
l 学习hg
主要说下私下怎么熟悉hg,启动hg server,自己多熟悉熟悉操作,特别是后面的merge等操作
Note
hg serve
启动一个 WEB 服务器以便当前版本库能通过 Internet 访问
快速建立中央库最简陋的方法是使用 Mercurial 内置的 WEB 服务器 – 你所作的仅仅是用 hg init 创建一个版本库, 然后用 hg serve 启动 WEB 服务. 默认情况下, 它会占用 8000 端口.
C:\> mkdir CentralRepo
C:\> cd CentralRepo
C:\CentralRepo> hg init
C:\CentralRepo> hg serve
这台 PC 的主机名是 joel.example.com, 我只要用浏览器登录 http://joel.example.com:8000/ 便可看到服务器已经启动并正在运行, 虽然版本库还是空白一片.
在linux里面,cat /etc/hostname ,里面就是主机名字
Note
hg clone
获取版本库的完整副本
一旦中央 WEB 服务器开始服务, 我可以从服务器 克隆 (clone) 版本库到我的个人 PC 自主使用. 这个版本库现在还是空的, 所以我克隆后得到的也是空白库.
C:\Users\joel> hg clone http://joel.example.com:8000/ recipes
no changes found
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\Users\joel> cd recipes
C:\Users\joel\recipes> dir
Volume in drive C has no label.
Volume Serial Number is 84BD-9C2C
Directory of C:\Users\joel\recipes
02/08/2010 02:46 PM <DIR> .
02/08/2010 02:46 PM <DIR> ..
02/08/2010 02:46 PM <DIR> .hg
0 File(s) 0 bytes
3 Dir(s) 41,852,125,184 bytes free
现在, 我们新建一个名为 guac 的文件, 记录本人有名的鳄梨酱配方.
guac:
* 2 ripe avocados
* 1/2 red onion, minced (about 1/2 cup)
* 1-2 serrano chiles, stems and seeds removed, minced
* 2 tablespoons cilantro leaves, finely chopped
* 1 tablespoon of fresh lime or lemon juice
* 1/2 teaspoon coarse salt
* A dash of freshly grated black pepper
* 1/2 ripe tomato, seeds and pulp removed, chopped
Crunch all ingredients together.
Serve with tortilla chips.
我将添加这个文件, 并作为我的第一个官方版本提交:
C:\Users\joel\recipes> hg add
adding guac
C:\Users\joel\recipes> hg commit
以及提交摘要:
现在, 我要编辑这个文件, 做些小改动, 这样版本库里就会留下些历史记录了.
接着提交这次变更:
C:\Users\joel\recipes> hg status
M guac
C:\Users\joel\recipes> hg diff guac
diff -r c1fb7e7fbe50 guac
--- a/guac Mon Feb 08 14:50:08 2010 -0500
+++ b/guac Mon Feb 08 14:51:08 2010 -0500
@@ -7,5 +7,5 @@
* A dash of freshly grated black pepper
* 1/2 ripe tomato, seeds and pulp removed, chopped
-Crunch all ingredients together.
+Smoosh all ingredients together.
Serve with tortilla chips.
C:\Users\joel\recipes> hg com -m "Change crunch to smoosh"
C:\Users\joel\recipes> hg log
changeset: 1:a52881ed530d
tag: tip
user: Joel Spolsky <joel@joelonsoftware.com>
date: Mon Feb 08 14:51:18 2010 -0500
summary: Change crunch to smoosh
changeset: 0:c1fb7e7fbe50
user: Joel Spolsky <joel@joelonsoftware.com>
date: Mon Feb 08 14:50:08 2010 -0500
summary: Initial version of guacamole recipe
注意我这次提交的时候, 头一次使用了 -m 参数. 这只是在命令行下, 不通过编辑器输入提交摘要的一个方法.
OK, 我们在哪儿? 到目前为止, 我能访问中央库, 还克隆了一份本地库. 我已经做了两次变更并提交到本地库, 但是这些变更只存在于我的本地库 – 它们还没有进入中央库. 所以现在的状况是:
Note
hg push
把一个版本库的新增变更推送到另一个版本库
现在我将使用 hg push 命令, 把我的变更从我的本地库 推入 到中央库:
C:\Users\joel\recipes> hg push
pushing to http://joel.example.com:8000/
searching for changes
ssl required
我靠, 居然报错. 我暂时不考虑随便运行一个 WEB 服务器, 还允许任何人把他们那愚蠢的变更推到中央库所带来的安全问题. 忍耐一小会; 我要去配置一下服务器, 让任何人都可以为所欲为. 这需要编辑一下 .hg\hgrc 文件.
.hg\hgrc:
[web]
push_ssl=False
allow_push=*
显然, 这是很危险的, 但是如果你处在一个安全的局域网环境下工作, 有一个优秀的防火墙, 而且你信任局域网中的每个人, 这样的话是安全的. 否则, 你可能要去看看手册中关于安全的进阶章节.
好, 我们重新启动服务器:
C:\CentralRepo> hg serve
现在我应该可以 push 变更集了:
Hg push的时候报错:abort: no username supplied (see "hg help config")
Step 1:先到对应目录下的.hg目录,输入以下指令:
$ cd .hg
Step 2:修改在.hg目录下的hgrc档案:
$ vi hgrc
---------------------------------------------------------------
hgrc的档案內容:
[paths]
default = http://javaforge.com/hg/HelloWorld
Step 3:请在档案內加入以下內容:
[ui]
username = John Wu <john@example.com>
Username后面可以是只有名称或E-mail,上面是完整的显示方式。
C:\Users\joel\recipes> hg push
pushing to http://joel.example.com:8000/
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
Yay! 现在的状况变成这样了:
我知道你在想什么. 你在想, “喔呦, Joel, 太奇怪了. 为什么这些版本库里包含的是 变更 而不是 文件 呢? guac 文件在哪儿?”
是的, 很诡异. 但这就是分布式版本控制的工作方式. 版本库就是一个包含大量变更的堆栈. 把变更想象成一块干净的透明毯子. 现在你有一捆这样的透明毯子, 你把它们按顺序堆叠起来, 最新变更放在最上面, 然后从上往下俯视, 注意! – 你看到的便是当前最新版本的文件. 随着你从栈顶慢慢掀走透明毯, 你会看到越来越老的版本.
现在, 我们可以通过浏览器感受一下中央版本库: