Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

Git equivalents of most common Mercurial commands?

I've been using Mercurial but would like to do a quick demo of Git.

What are the Git equivalents of:

hg init . # start a project in the current directory
hg addremove # look for any added or deleted files
hg commit -m "comment" # commit any uncomitted changes
hg status # what have i changed since the last commit?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Git-HG rosetta stone is not bad

There are a few other gotchas between the two not mentioned there. This list was cribbed from my own blog post when I went the other way (git -> hg).

Hg .hgignore, syntax: glob is the same behaviour as git's .gitignore.

Git .git/config, ~/.gitconfig, use git-config to modify the values
Hg .hg/hgrc, ~/.hgrc, use hg help -c config

Git git commit -v<br> Hg hg diff | less; hg commit

Git gitk<br> Hg hg view, or thg from [TortoiseHg][1]

Git git gui<br> Hg Mercurial doesn't ship GUI to select changesets, only console hg record command.

Git git rebase<br> Hg hg rebase. For git rebase --interactive there's hg histedit, or Mercurial Queues

Git git push URL ; git remote add origin URL<br> Hg hg push URL; $EDITOR .hg/hgrc ; [paths] default = URL

Git gitk, git log origin/master..HEAD<br> Hg hg outgoing

Git git format-patch RANGE<br> Hg hg email -m filename -o

Git git add . ; Note the dot
Hg hg add ; No dot needed.

Git git checkout REVISION-KEY<br> Hg hg update CHANGESET


Just to fill the blanks, some of the most useful commands from Mercurial:

Hg hg record
Git git add -p; git commit

Hg hg inc [URL]
Git No real equivalent. You can only do equivalent of hg pull; hg log -r .:

Hg hg out URL
Git Please add if you know how.

For merge conflict resolution, the hg resolve command in Mercurial has a few options that change the behaviour:

Hg hg resolve -m FILE (marks the file as having been resolved by manually fixing up the conflict problem)
Git git add FILE

Hg hg resolve -u FILE marks the file as having been unresolved
Git git reset HEAD FILE to unstage the file

Hg hg resolve -l (lists files with resolved/unresolved conflicts)
Git git status - files that merged cleanly are added to the index automatically, those that are not have conflicts

Hg hg resolve FILE (after a merge, attempts to re-merge the file)
Git no equivalent for re-merging that I know of.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...