协同方法
在所有开发人员中指定一个Server,类似于svn repo。其他人(Client)的代码是server的副本,修改、测试稳定后立即合并回server(最好通过server的pull方法实现,比client push更保险),server将client提交的更新与自己的更新合并(merge)后立即push回client,要注意的是server在pull之前要确保working directory中没有未提交的更改(未完成功能,用"hg st"命令的输出是否为空来检验,为空说明没有未完成功能),因为merge后必须提交一个“合并版本”到版本库,如果有未完成功能,也会被提交到版本库中。
A和B在同步过代码后,如果A提交了新changeset,而此期间B没有提交过,则A可以把变化push给B,这时B不需要merge,只update即可,update后可以用hg log -l 1 -v查看哪些文件发生了变化,以及A的提交说明;
整个协同过程中不需要新建branch或者bookmark,估计是最简单的分布式版本控制系统的协同模型。
试验过程
Server(username: Li Chao)新建一个repo,添加文件,提交changeset,Client(username: chadOnPC)clone此repo,修改其中一个文件,与此同时Li Chao修改了另一个文件,chadOnPC将修改push回笔记本,Li Chao合并两部分修改,再修改这两个文件,push到Client,由于这期间Client没有修改,所以只要update就把Server push的内容更新到了working directory中。
========== Server ================
c:\tmp\HgRepo>hg init // 新建两个文件:forChadLaptop.txt和forChadPC.txt并写一些内容在文件里 c:\tmp\HgRepo>hg add .txt c:\tmp\HgRepo>hg stat A forChadLaptop.txt A forChadPC.txt c:\tmp\HgRepo>hg ci -m "first checkin" c:\tmp\HgRepo>hg log changeset: 0:fd200857b086 tag: tip user: Li Chao date: Thu Apr 25 11:32:24 2013 +0800 summary: first checkin c:\tmp\HgRepo>hg heads changeset: 0:fd200857b086 tag: tip user: Li Chao date: Thu Apr 25 11:32:24 2013 +0800 summary: first checkin c:\tmp\HgRepo>hg serve listening at http://chadlaptop:8000/ (bound to :8000) =========== Client ============== E:\lc\clonedRepo>hg clone http://chadlaptop:8000/ ... E:\lc\clonedRepo>hg log changeset: 0:fd200857b086 tag: tip user: Li Chao date: Thu Apr 25 11:32:24 2013 +0800 files: forChadLaptop.txt forChadPC.txt description: first checkin E:\lc\clonedRepo>hg st // edit file "forChadPC.txt" E:\lc\clonedRepo>hg st M forChadPC.txt E:\lc\clonedRepo>hg ci -m "first on pc" forChadPC.txt committed changeset 1:2c5fbbb6645b E:\lc\clonedRepo>hg log changeset: 1:2c5fbbb6645b tag: tip user: chadOnPC date: Thu Apr 25 11:42:09 2013 +0800 files: forChadPC.txt description: first on pc changeset: 0:fd200857b086 user: Li Chao date: Thu Apr 25 11:32:24 2013 +0800 files: forChadLaptop.txt forChadPC.txt description: first checkin / 需要在被push的repo的.hg/hgrc文件中增加如下内容(如果文件不存在新建之): * [web] * push_ssl = false * allow_push = * / E:\lc\clonedRepo>hg push http://chadlaptop:8000/ pushing to http://chadlaptop:8000/ searching for changes 1 changesets found remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files ============= Server ================== // 修改forChadLaptop.txt文件 c:\tmp\HgRepo>hg st M forChadLaptop.txt // 修改被感知到 c:\tmp\HgRepo>hg heads changeset: 1:2c5fbbb6645b tag: tip user: chadOnPC date: Thu Apr 25 11:42:09 2013 +0800 summary: first on pc // 与push之前笔记本上"hg heads"命令相比,head变成了push过来的那个changeset c:\tmp\HgRepo>hg st M forChadLaptop.txt // push不改变working dirctory中的文件 c:\tmp\HgRepo>hg ci -m "second commit on laptop" created new head c:\tmp\HgRepo>hg heads changeset: 2:42809e7d6c58 tag: tip parent: 0:fd200857b086 user: Li Chao date: Thu Apr 25 11:54:05 2013 +0800 summary: second commit on laptop changeset: 1:2c5fbbb6645b user: chadOnPC date: Thu Apr 25 11:42:09 2013 +0800 summary: first on pc // head变成了两个 c:\tmp\HgRepo>hg branch default // branch始终只有default一个 c:\tmp\HgRepo>hg merge 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) c:\tmp\HgRepo>hg st M forChadPC.txt // merge命令改变了working directory中文件的内容 c:\tmp\HgRepo>hg ci -m "merge from pc" c:\tmp\HgRepo>hg log changeset: 3:ba028970a1d0 tag: tip parent: 2:42809e7d6c58 parent: 1:2c5fbbb6645b user: Li Chao date: Thu Apr 25 11:57:17 2013 +0800 summary: merge from pc changeset: 2:42809e7d6c58 parent: 0:fd200857b086 user: Li Chao date: Thu Apr 25 11:54:05 2013 +0800 summary: second commit on laptop changeset: 1:2c5fbbb6645b user: chadOnPC date: Thu Apr 25 11:42:09 2013 +0800 summary: first on pc changeset: 0:fd200857b086 user: Li Chao date: Thu Apr 25 11:32:24 2013 +0800 summary: first checkin =========== Client =====================
E:\lc\clonedRepo>hg serve
=========== Server ===================
c:\tmp\HgRepo>hg push http://china-a9598ee91:8000/
...
=========== Client ===============
E:\lc\clonedRepo>hg update // 由于Client没有同时修改代码,所以不需要merge,update即可