hg和git命令对照表

来源 https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone

Git hg rosetta stone

 
muxator edited this page on 10 Mar 2017 · 50 revisions

The sympy git server is at https://github.com/sympy/sympy . The main Sympy repository may be cloned with git clone git://github.com/sympy/sympy.git.

The first and the most important thing is that you should understand that git is different. For example it uses staging area (so called index) for iteratively preparing commits. This and other great and unique features of git make it the preference of many developers, so go read its documentation!

Here is a nice cheatsheet which will probably make your life easier in the beginning: https://jan-krueger.net/development/git-cheat-sheet-extended-edition

Being said all this, now comes a simplified mapping between hg commands and git commands. Use it with care -- there are some semantic differences ...


If you know how to use hg very well and just looking at how to do the same things in git, this page is right for you. Use it like a dictionary hg -> git. Some equivalent git commands may seem more complex than the corresponding hg counterparts; that's because the natural flow of work in git doesn't map 1:1 to Mercurial. But the point here is that if you are used to some specific workflow in hg, it can be directly translated to git using the table below and it does exactly the same thing as you are expecting it to.

When editing this wiki page, please only add an exact equivalent to some hg command; a full explanation can always be found somewhere else on the net.

Table of Contents

Rosetta Stone

hg git
hg cat -r rev some_file git show rev:some_file
hg clone http://hg.sympy.org/sympy-git.hg git clone git://git.sympy.org/sympy.git
hg clone -U http://hg.sympy.org/sympy-git.hg git clone --bare git://git.sympy.org/sympy.git
hg diff git diff HEAD
hg diff -r A -r B git diff A^..B
hg status git status
hg status -c git ls-files -t | grep '^H'
hg manifest git ls-tree -r --name-only --full-tree HEAD
hg parents git show --pretty=format:'%P' -s
hg commit git commit -a
hg record git add -p; git commit # or, for a more detailed interface: git add -i; git commit
hg email -r tip git send-email HEAD^ # or: git format-patch HEAD^ ; git send-email 0001-Add-whitespace.patch
hg view gitk, git gui
hg help command git help command
~/.hgrc ~/.gitconfig
.hg/hgrc .git/config
hg paths git remote -v
editing paths in .hg/hgrc git remote add name url # see "git help remote" for more info how to edit paths; alternatively, you can edit them by hand in .git/config too
.hgignore .gitignore
.hg/hgrc [ui] ignore .git/info/exclude
hg add git add (note, it adds _content_ to index; can work on a hunk-by-hunk basis with -p!)
hg rm git rm
hg push git push
hg pull git fetch
hg pull -u git pull
hg addremove git add -A (or: git add .; git ls-files --deleted xargs git rm)
hg revert -a git reset --hard
hg revert some_file git checkout some_file
hg purge git clean -fd
hg purge --all git clean -fdx
hg strip 2fccd4c git reset --hard 2fccd4c^ (on a normal repository)
git reset --soft 2fccd4c^ (on a bare repository)
hg forget git rm --cached (reference: stackoverflow)
hg export git format-patch
hg import --no-commit some.patch git apply some.patch
hg import some.patch git am some.patch
hg out git fetch && git log origin/master..
hg in git fetch && git log ..origin/master
hg update tip git checkout HEAD # or this: "git checkout master", or "git merge FETCH_HEAD", depending on what you did before this
hg update -C git checkout -f
hg update some.branch git checkout some.branch # Note that "git branch some.branch" is not the same as this.
hg up --date 2014-01-01 git checkout `git rev-list -n 1 --before="2014-01-01" master`
hg qimport stg something (A separate patch manager extension is probably not necessary in git -- normal workflow combined with git rebase -i should cover your needs)
hg qpush (see hg qimport)
hg qpop (see hg qimport)
hg qimport -r tip ?
hg qnew -f some.patch ?
hg resolve -a -m git add -u
hg root git rev-parse --show-toplevel
hg log -G (old way: hg glog) git log --graph --all --decorate # or: git log --graph --all;
hg verify git fsck
hg branches git branch -a
hg branch git rev-parse --abbrev-ref HEAD
hg rollback git reset HEAD~
hg backout git revert

Setup

~/.hgrc:

 [ui]
username = Ondrej Certik <ondrej@certik.cz>

~/.gitconfig:

 [user]
name = Ondrej Certik
email = ondrej@certik.cz [color]
ui = auto [color]
decorate = short [alias]
ci = commit
di = diff --color-words
st = status # aliases that match the hg in / out commands
out = !git fetch && git log FETCH_HEAD..
outgoing = !git fetch && git log FETCH_HEAD..
in = !git fetch && git log ..FETCH_HEAD
incoming = !git fetch && git log ..FETCH_HEAD

More Information

One can find some info here:

and at many other pages.

Tips

 - use gitk to visualize history (much more capable than "hg vi")
- use git gui to visually stage/unstage what you are preparing for commit
to index (it too can work on hunk-by-hunk basis)
- git stash is your friend
- git rebase --interactive is your friend too :)
- windows users: either use cygwin or msysgit:
https://code.google.com/p/msysgit/
 - don't try to project your usual habits - open your mind, and maybe you'll
discover much more superior workflow. (yes, this needs hard work and RTFM,
and being ready that FM sometimes differ from what software actually does)
- Add this
 parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
# __git_ps1 "(%s)"
# use the second line instead if you have bash autocompletion for git enabled
}
PS1="\w\$(parse_git_branch) $ "
   to your promptstring to show current branch when in a git-tracked directory.
(see http://b.lesseverything.com/2008/3/25/got-git-howto-git-and-github)

git -> hg conversion

You can use this script:

#! /bin/bash

work=`mktemp -t -d sym.XXX`
git format-patch -k -p -o $work master..HEAD
# add a new line after the subject line so that Mercurial imports it fine.
sed -i '4a\\' $work/*
cd ~/repos/sympy.hg/
hg import $work/*
rm -r $work

to convert all patches between master..HEAD to mercurial repository sitting at ~/repos/sympy.hg/.

Alternatively, you could use the hg-git Mercurial plugin.

how to checkout remote branch

Start with some repository, for example create a new one from scratch:

$ mkdir sympy
$ cd sympy
$ git init

or clone our official repository:

$ git clone git://git.sympy.org/sympy.git
$ cd sympy

Now let's say you want to checkout some branch from git://github.com/certik/sympy.git. The canonical way is to add it to your remotes:

$ git remote add ondrej git://github.com/certik/sympy.git

Then fetch all branches from there into your remote branches:

$ git fetch ondrej

You can now list them with "git branch -r", or examine them with "git log ondrej/some_branch". Finally, to checkout the mpmath5 branch, do:

$ git checkout -b mpmath5 ondrej/mpmath5

================= End

hg和git命令对照表的更多相关文章

  1. 常用Git命令汇总

    常用Git命令汇总 跟着R哥来到了新公司(一个从硬件向互联网转型中的公司),新公司以前的代码基本是使用SVN做版本控制,甚至有些代码没有做版本控制,所以R哥叫HG做了一次Git分享,准备把公司所有的代 ...

  2. Git初探--笔记整理和Git命令详解

    几个重要的概念 首先先明确几个概念: WorkPlace : 工作区 Index: 暂存区 Repository: 本地仓库/版本库 Remote: 远程仓库 当在Remote(如Github)上面c ...

  3. 工作中常用的git命令

    一 常用Git命令 git clone:(区分SSH or HTTP) git init:初始化仓库 二 Git命令详解 Git Bash下,cd /c git clone,从远程Git版本库克隆一份 ...

  4. 常用 Git 命令清单

    我每天使用 Git ,但是很多命令记不住. 一般来说,日常使用只要记住下图6个命令,就可以了.但是熟练使用,恐怕要记住60-100个命令. 下面是我整理的常用 Git 命令清单.几个专用名词的译名如下 ...

  5. 常look的Git命令

    常用的Git命令   命令  简要说明 git add 添加至暂存区 git add–interactive 交互式添加 git apply   应用补丁 git am  应用邮件格式补丁 git a ...

  6. ***Linux下使用git命令及github项目

    在linux下搭建git环境1.创建Github账号,https://github.com2.Linux创建SSH密钥: ssh-keygen  ##一直默认就可以了 3.将公钥加入到Github账户 ...

  7. 我所记录的git命令(非常实用)

    一.前言 记录一下工作中常用到的git命令,只是简单的笔记,欢迎大家交流... [ 顺便问下园友们,怎么感觉博客园发布的博客搜索有时都搜不到,后台编辑能填的都填写了,还是觉得搜索排名不高? 相同的标题 ...

  8. GIT命令行的使用

    新手了解 有不对的地方指点下 首先, 了解下什么是GIT,GIT是一款开元的分布式版本控制工具, 在世界上的所有分布式版本控制工具中,GIT是最简单,最流行,同时也是最常用的 相比于其他版本的控制工具 ...

  9. 简明 Git 命令速查表(中文版)

    原文引用地址:https://github.com/flyhigher139/Git-Cheat-Sheet/blob/master/Git%20Cheat%20Sheet-Zh.md在Github上 ...

随机推荐

  1. go get 碰壁怎么办?

    如果要让go get顺利进行,必须注意2个问题:     1.墙:2.墙: 解决办法是安装和配置shadowsocks和polipo.shadowsocks是socks5协议,polipo是将sock ...

  2. Angularjs演示Service功能

    在angularjs中,我们可以自定义自己的service.可以说得是自定义的方法,函数. 下面我们一步一步来演示吧:首先为angularjs定义一个app: var demoApp = angula ...

  3. b/s程序真的很方便部署吗

    公共应用当然是web系统,这个不说,我说的是企业应用. 最近一些年在企业开发中都提倡web应用,仿佛winform可以结束了,但真的这样吗?最近几天的真实经历如下: 我们部门新开发了一套系统要上线,由 ...

  4. 来不及说什么了,Python 运维开发剁手价仅剩最后 2 天

    51reboot 运维开发又双叒叕的搞活动了—— Python 运维开发 18 天训练营课程, 剁手价1299 最后2天 上课方式:网络直播/面授(仅限北京) DAY1 - DAY4 Python3 ...

  5. php5.6安装Zend Opcache扩展

    假设php5.6安装路径为/data2/php[root@nextcloud src]# pwd/usr/local/src[root@nextcloud src]# wget http://pecl ...

  6. PairProject——结对编程

    成员:12061162  王骜 12061225  钟毅恒 一.合作过程中的照片 . 二.结对编程的优缺点 优点: 1)在编程过程中,任何一段代码都不断地复审,同时避免了将写代码的责任抛给一个人的问题 ...

  7. Linux内核分析作业 NO.6

    进程的描述和进程的创建 于佳心  原创作品转载请注明出处  <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-100002900 ...

  8. java计算器项目

    简单的java计算器项目   题目:java计算器项目 一. 题目简介: 一个能进行加减乘除四则运算的小程序 Github链接:https://github.com/lizhenbin/test/tr ...

  9. 个人实验 github地址:https://github.com/quchengyu/cher

    一.实践目的 1.掌握类的定义,对象的创建. 2.掌握实现封装.继承.多态的方法,掌握各种修饰符的使用. 3.掌握将对象数组作为方法的参数和返回值. 4.掌握抽象类与接口的概念及实现,理解动态绑定机制 ...

  10. 广商博客冲刺第四五天new

    第三天沖刺傳送門 第六七天沖刺傳送門 以上的前台设计架构已经完成了,现在来完成前台的安卓设计. 首先我们配置了Android SDK Manager 使得程序能在安卓环境下运行. 这就完成了前台安卓的 ...