Hg常用命令和场景(一)--线上代码更新 和 项目代码提交

1.  获取一份代码,用于测试环境和线上环境(相较于git,更多用的是clone):
hg clone http://lixl:[email protected]/hg/xxx

2. 项目开发,用于开发环境:
(在 1 的基础上进行开发之后)
查看当前更改内容,通常在要在commit之前用于确认:
hg status

比hg status更进一步,查看具体的变化(相较于git,这里最好加上"| more"):
hg diff

如有新添加文件则:
hg add file1.py

如有删除文件则:
hg rm file2.py

#提交修改到本地仓库
[lixinglei@bogon project1]$ hg commit  file3.py service/file4.py  -m "这里填写注释"
abort: no username supplied (see "hg help config")

第一次操作会报错,根据提示信息操作:
[lixinglei@bogon project1]$ hg help config
Configuration Files

    Mercurial reads configuration data from several files, if they exist. Below we list the most specific file first.

    On Windows, these configuration files are read:

    - "<repo>\.hg\hgrc"
    - "%USERPROFILE%\.hgrc"
    - "%USERPROFILE%\Mercurial.ini"
    - "%HOME%\.hgrc"
    - "%HOME%\Mercurial.ini"
    - "C:\Mercurial\Mercurial.ini"
    - "HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial"
    - "<install-dir>\Mercurial.ini"

    On Unix, these files are read:

    - "<repo>/.hg/hgrc"
    - "$HOME/.hgrc"
    - "/etc/mercurial/hgrc"
    - "/etc/mercurial/hgrc.d/*.rc"
    - "<install-root>/etc/mercurial/hgrc"
    - "<install-root>/etc/mercurial/hgrc.d/*.rc"

    The configuration files for Mercurial use a simple ini-file format. A configuration file consists of sections, led by a
    "[section]" header and followed by "name = value" entries:

      [ui]
      username = Firstname Lastname <[email protected]>
      verbose = True

    This above entries will be referred to as "ui.username" and "ui.verbose", respectively. Please see the hgrc man page for a
    full description of the possible configuration values:

    - on Unix-like systems: "man hgrc"
    - online: http://www.selenic.com/mercurial/hgrc.5.html

添加username到 .hg/hgrc中:
[lixinglei@bogon project1]$ vim .hg/hgrc
  1 [paths]
  2 default = http://lixl:[email protected]/hg/xxx
  3 [ui]
  4 username = lixl<[email protected]>

#从远端拉代码,如果上面已经配置了地址,可以直接hg pull
[lixinglei@bogon project1]$ hg pull http://lixl:[email protected]/hg/xxx
pulling from http://lixl:***@192.168.XXX.XXX/hg/xxx
searching for changes
adding changesets
adding manifests
adding file changes
added 3 changesets with 4 changes to 3 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

#合并代码,hg的pull 和 git 的pull,最大的区别在于没有merge的过程,因此需要手动的merge,如果本地没有更新,则直接使用update,如果本地有版本修改,则需要先通过hg log 查看pull之后的最新版本,然后将本地库版本merge到pull到的最新版本上。
[lixinglei@bogon project1]$ hg update
4 files updated, 0 files merged, 0 files removed, 0 files unresolved

#提交代码到远端
[lixinglei@bogon project1]$ hg push


你可能感兴趣的:(git,hg)