hg和git命令对照表(值得拥有)


转自:https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone


Rosetta Stone

hg git
hg cat -r rev some_file git show rev:some_file
hg clonehttp://hg.sympy.org/sympy-git.hg git clone git://git.sympy.org/sympy.git
hg clone -Uhttp://hg.sympy.org/sympy-git.hg git clone --bare git://git.sympy.org/sympy.git
hg diff git diff HEAD
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^
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 FETCH_HEAD..master
hg in git fetch && git log master..FETCH_HEAD
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 glog git log --graph --all --decorate # or: git log --graph --all;
hg verify git fsck
hg branches git branch -a
hg rollback git reset HEAD~

Setup

~/.hgrc:

 [ui]
 username = Ondrej Certik 

~/.gitconfig:

 [user]
     name = Ondrej Certik
     email = [email protected]

 [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:

  • http://git.or.cz/course/svn.html
  • http://www.redhatmagazine.com/2008/05/02/shipping-quality-code-with-git/
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:
   http://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/.

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

你可能感兴趣的:(开源项目学习)