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!

  • git project page: https://git-scm.com/
  • git faq explaining many things: https://git.wiki.kernel.org/index.php/GitFaq
    make sure to read mails referenced from the faq -- they are really brilliant, e.g.  Linus on git and renames
  • git wiki: https://git.wiki.kernel.org/index.php/Main_Page
  • git documentation: https://git-scm.com/doc

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
  • Setup
  • More Information
  • Tips
  • git -> hg conversion
  • how to checkout remote branch

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 Certikemail = ondrej@certik.cz[color]ui = auto[color]decorate = short[alias]ci = commitdi = diff --color-wordsst = status# aliases that match the hg in / out commandsout      = !git fetch && git log FETCH_HEAD..outgoing = !git fetch && git log FETCH_HEAD..in       = !git fetch && git log ..FETCH_HEADincoming = !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 committo 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'lldiscover 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/bashwork=`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. hg和git命令对照表(值得拥有)

    转自:https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone Rosetta Stone hg git hg cat -r rev some_ ...

  2. Git可视化工具SourceTree使用手册:中英文/命令对照表

    目录 前言 中英文/命令对照表 顶部操作栏 左侧树 右键工作副本 右键本地分支 右键标签 右键origin 右键远程分支 右键贮藏 右侧工作区 右键工作副本-已/未暂存文件 右键分支-分支列表中的节点 ...

  3. hg转git的那些事

    其实网上的信息真的很多很多了,不管是度娘还是谷歌,搜关键字"git",所有的信息都有了.最简单的入门也好,高级操作也罢,在这个信息爆炸的时代,想要的不想要的信息,都触手可及.那我写 ...

  4. 常用 Git 命令清单

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

  5. 使用git命令上传本地文件到GitHub上

    1.官网下载git并且anz安装 2.在Github上申请账号 3.在本地使用git命令生成私钥和公钥 连续按三次 回车键 $ ssh-keygen -t rsa -C "账号" ...

  6. java代码操作git_JGit--实现Git命令操作的Java API

    问题来源:最近在做一个项目,其中有一块需要用户上传代码到服务器中,然后分析用户所传的代码,传代码最直接的方式就是用户打个包上传,但是后期再分析代码的时候还要代码实现解压上传的代码,操作起来比较复杂. ...

  7. 如何用git命令行上传本地代码到github

    如何用git命令行上传本地代码到github 2016年09月19日 16:10:36 阅读数:9337 注意:安装的前提条件是配置好git的相关环境或者安装好git.exe,此处不再重点提及 上传的 ...

  8. 这个神了,一目了然,确实好,看小姐姐用动图展示10大Git命令

    选自dev.to  作者:Lydia Hallie 机器之心编译  参与:Panda.杜伟 git merge.git rebase.git reset.git revert.git fetch.gi ...

  9. 最常用的20个Git命令与示例,你都会了么?

    ◆ ◆ ◆  ◆ ◆ 既然你(大概)知道Git是什么以及它是如何工作的,那么看看如何使用最常见的20个Git命令的例子. 以下是正在涵盖的Git命令: git config git init git ...

最新文章

  1. man nfsd(rpc.nfsd中文手册)
  2. vue点击定位到指定位置_百度地图vue-baidu-map自动定位,鼠标选点并进行逆解析,地区检索,使用案列以及解决方案...
  3. Asp.Net微型服务器使用次数统计
  4. 结对项目之需求分析与原型模型设计
  5. python图片横向合并_python实现图片横向和纵向拼接
  6. 使用mysql备份工具innobackupex进行本地数据备份、恢复操作实例
  7. 单片机STM8S测量电压电路_单片机电路设计中的10个难点
  8. 你大爷还是你大爷!三星震撼首发折叠屏智能手机Galaxy Fold
  9. P1510 精卫填海
  10. spring catch了异常还是回滚了_干货:Spring 踩坑之@Transactional 神奇失效
  11. 2022年小米路由器安装使用mixbox遇到的问题
  12. 来啊battle啊,Java和Python你站哪个?
  13. ffmpeg的安装以及transform360插件的安装
  14. UE支持的Codec对比
  15. Type of the default value for 'songs' prop must be a function
  16. 问题描述:宏代码导致无法打开文件
  17. Freemarker讲解
  18. 链接器lds文件简介
  19. led trigger
  20. 三、使用Teigha.net打开CAD(.dwg/.dxf)文件,并显示到panel界面绑定事件

热门文章

  1. Java、JSP网上问卷调查系统
  2. 动物系列3D虚拟解剖软件助力畜牧兽医专业学习
  3. 记 · leo · code 2019
  4. 网络精英赛模拟练习(7)
  5. 【渝粤题库】国家开放大学2021春2410中国古代文学(B)(2)题目
  6. 定时锁定计算机代码bat,用bat实现的自动关机的代码
  7. 长沙市六中学生寒假社会实践活动在湖南智慧教育装备展示体验中心开展
  8. Android 13 针对 Intent filters 安全的再加强
  9. vue项目如何减少app.js和vender.js的体积
  10. repo manifest文件