例说hg(六)———— hg branch 创建分支

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ningxialieri/article/details/17967991

本文由博主原创,转载请注明出处(保留此处和链接):

一日二十四挨踢http://1024it.net/?p=143

hg专题文章:

例说hg(一)————hg sum 与hg tip区别

例说hg(二)———— hg merge的使用

例说hg(三)———— hg的图形界面安装

例说hg(四)———— 杂说hg使用场景

例说hg(五)————创建repository

例说hg(六)———— hg branch 创建分支


 


开篇:

        branch (分支)應該也是 Hg 最重要的技能之一,在一個多人專案的開發過程中我們有時候要開發新功能,有時候是要修正某個Bug,有時候想要測試某個特異功能能不能 work ,這時候我們通常都會從主 branch 再開出一條新的 branch 來做,這支新開的 branch 會帶著你的主 branch 目前的最新狀態,當你完成你所要開發的新功能/ Bug 修正後確認沒問題就再把它 merge(合併)回主 Branch ,如此便完成了新功能的開發或是 Bug 的修正,因此每個人都可以從主 branch 拉一條新的 branch 來做自己想做的事,再來我們好好了解一下 branch 的使用。(摘自


hg branch 的实例操作:


利用hg创建新的Branch:

robin@ubuntu:~/workspace/c_wspace/testhg$ hg branch newbranch      //创建新的branch————newbranch
marked working directory as branch newbranch
(branches are permanent and global, did you want a bookmark?)
robin@ubuntu:~/workspace/c_wspace/testhg$ vim test.txt            //新创建的branch只有在下次commit时,才能真正生成。
                                                                  //在此编辑test.txt来做commit操作,目的是让newbranch真正生成。
                                                                  //此处可以不用编辑test.txt,直接做一次commit操作来生成新的branch
robin@ubuntu:~/workspace/c_wspace/testhg$ hg commit -u "RobinLau" -m "add new branch newbranch"


把本地创建的branch上传到remote:
robin@ubuntu:~/workspace/c_wspace/testhg$ hg push  --new-branch    //把新创建的branch上传到远端,即BB仓库中。
pushing to https://[email protected]/RobinLau/testhg
http authorization required
realm: Bitbucket.org HTTP
user: RobinLau
password: 
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 0 changes to 0 files (+1 heads)


利用hg切换不同的branch:

robin@ubuntu:~/workspace/c_wspace/testhg$ hg update lina       //切换分支,切换到分支lina
1 files updated, 0 files merged, 2 files removed, 0 files unresolved
robin@ubuntu:~/workspace/c_wspace/testhg$ hg sum 
parent: 3:8a1d75c5a0d9 
 test lina branch
branch: lina
commit: (clean)
update: (current)

查看当前的branch:

testhg$ hg branch           //查看当前分支名
new


操作结果:


上图显示了我创建的三个分支new、lina、newbranch


结论:

1. hg branch ————显示当前所在的分支

2. hg branch + “要创建的分支名”    ————创建新的分支(这里必须进行一次hg commit操作才能真正创建分支)

3. hg push --new-branch ————把在本地创建的branch 上传到远端,即BB上。

4.hg update + "已有的分支名" ———— 切换到想要的分支。

5.hg update -r + ”版本號“ ———— 切換到你所指定的版本上


猜你喜欢

转载自blog.csdn.net/ningxialieri/article/details/17967991