hg 配置使用

公司版本控制用的是hg,总结了下自己在使用过程中的经验。

l Ubuntu  下安装TortoiseHG

1、加入ppa:mercurial

2、加入ppa:TortoiseHG
3update apt
4install TortoiseHG
5、重启系统
6OK 

@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可以用来生成privatepublic密钥.将生成的public密钥拷贝到远程机器后,可以使ssh到另外一台机器的登陆不用密码.具体方法如下.

1. 生成密钥

在本地机器中的~/.ssh/目录下执行下命令,

ssh-keygen -t dsa

将生成两个文件,id_dsaid_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

http://bucunzai.net/hginit/ 

主要说下私下怎么熟悉hg,启动hg server,自己多熟悉熟悉操作,特别是后面的merge等操作

hg serve

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 ,里面就是主机名字

hg clone

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, 我们在哪儿到目前为止我能访问中央库还克隆了一份本地库我已经做了两次变更并提交到本地库但是这些变更只存在于我的本地库 – 它们还没有进入中央库所以现在的状况是:

hg push

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 文件在哪儿?

是的很诡异但这就是分布式版本控制的工作方式版本库就是一个包含大量变更的堆栈把变更想象成一块干净的透明毯子现在你有一捆这样的透明毯子你把它们按顺序堆叠起来最新变更放在最上面然后从上往下俯视注意– 你看到的便是当前最新版本的文件随着你从栈顶慢慢掀走透明毯你会看到越来越老的版本.

现在我们可以通过浏览器感受一下中央版本库:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值