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

 

場景一:hg 添加新文件的基本流程:

大家都知道,hg的基本流程:

hg  add +要上传的新文件(默认是本地所有的新建文件)

hg commit  -u  +用户名 -m  +提示消息(可以不用加-m)

hg  push

 

注意:

hg add 是把本地文件加入到cache中。

hg commit 是用来把cache中的文件提交到本地服务器

hg push 是把本地服务器的文件,上传的远程服务器上

hg addremove 是把本地已经删除,服务器上仍旧存在的文件从服务器上删除

 

 

場景二:取消hg add操作,和取消hg commit 操作方法:

我们在操作时会出现一些错误,需要取消掉hg add 或者 hg commit的操作,我们该如何做呢,下面是我遇到的问题及解决方案:

 

今天用hg  add 命令,出现如下提示:

cross-tools/gettext-0.18.2.1.tar.gz: up to 349 MB of RAM may be required to manage this file

(use 'hg revert cross-tools/gettext-0.18.2.1.tar.gz' to cancel the pending addition)

从提示可以看出,由于文件过大,建议我取消上传的文件,可见,取消hg  add的命令是 hg revert  +需要取消的文件。

 

 

同时,请教了下同事:用什么命令来取消hg  commit的效果呢?同事回答用hg  rollback 。

 

查了下rollback的help,如下:

robin@ubuntu:~/port_qemu$ hg rollback --help
hg rollback


roll back the last transaction (dangerous)


    This command should be used with care. There is only one level of
    rollback, and there is no way to undo a rollback. It will also restore the
    dirstate at the time of the last transaction, losing any dirstate changes
    since that time. This command does not alter the working directory.


    Transactions are used to encapsulate the effects of all commands that
    create new changesets or propagate existing changesets into a repository.
    For example, the following commands are transactional, and their effects
    can be rolled back:


    - commit
    - import
    - pull
    - push (with this repository as the destination)
    - unbundle


    To avoid permanent data loss, rollback will refuse to rollback a commit
    transaction if it isn't checked out. Use --force to override this
    protection.


    This command is not intended for use on public repositories. Once changes
    are visible for pull by other users, rolling a transaction back locally is
    ineffective (someone else may already have pulled the changes).
    Furthermore, a race is possible with readers of the repository; for
    example an in-progress pull from the repository may fail if a rollback is
    performed.


    Returns 0 on success, 1 if no rollback data is available.


options:


 -n --dry-run do not perform actions, just print output
 -f --force   ignore safety measures


use "hg -v help rollback" to show more info

 

場景三:獲取版本號所對應的哈希值,獲取哈希值對應的版本號

        大家都知道,hg為多人並行開發提供了方便,這也是這個版本控制工具的做大特點。但是,有時候我們在與共同開發者交流時,發現自己的版本號和小夥伴的版本號對應不上來。比如說,都是版本號20,但是提交的內容不同。這個差異的原意是:版本號是自己本地版本號的唯一標識。哪用什麽來標識遠端服務器版本號呢????發揮這個作用的就是我們的哈希值了,也就是版本號後面的那個值。如,changeset:   8:706a57d9f96b,8是版本號,706a57d9f96b是哈希值。

         我們該如何根據版本號獲取哈希值,如果根據哈希值獲取版本號呢?看下面的例子:

 

robin@ubuntu:~/workspace/myhg_wspace/opensource/rtags$ hg log -r 15
changeset:   15:7a2cfece7a8c
branch:      home
parent:      12:c9633976244a
parent:      14:342e4fb14402
user:        RobinLau
date:        Wed Jan 01 19:02:41 2014 +0800
summary:     merge 14 to 12(current)

robin@ubuntu:~/workspace/myhg_wspace/opensource/rtags$ hg log -r 7a2cfece7a8c
changeset:   15:7a2cfece7a8c
branch:      home
parent:      12:c9633976244a
parent:      14:342e4fb14402
user:        RobinLau
date:        Wed Jan 01 19:02:41 2014 +0800
summary:     merge 14 to 12(current)


結論:

 

hg log -r  + ”版本號/哈希值“————版本號與哈希值的相互獲取。

 

 

hg diff -r + '版本號"———— 查看當前版本與指定版本的不同

 

如果所列场景不能解决你所遇到的问题,请留言列出你所遇到的问题,楼主会补全。

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值