Skip to content

Mercurial (hg) to Git migration cheatsheet

savioret edited this page Nov 16, 2020 · 4 revisions
hg git
hg cat -r some_file git show :some_file
hg clone https://hg.host.org/project.hg git clone https://git.host.org/project.git
hg clone -U https://hg.host.org/project.hg git clone --bare https://git.host.org/project.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
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 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 note, it adds "content" to index;
can work on a hunk-by-hunk basis with -p!

git add
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
-A adds everything in the working tree
including new and deleted files
hg revert -a git reset --hard
hg revert some_file git checkout some_file
hg revert -r git checkout --
hg revert -r git show
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/..HEAD
git log @{push}.. (version nueva)
git fetch && git log FETCH_HEAD.. (MAL)
hg in git fetch && git log ..origin/master
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 qpush (see hg qimport)
hg qpop (see hg qimport)
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
hg backout git checkout HEAD~ --
lo deja como staged
hg resolve -l git diff --name-only --diff-filter=U
Show staged diff git diff —staged
hg diff -r tip git diff HEAD
hg revert ( staged ) git reset HEAD --
git reset
git restore --staged
hg commit -X file git add -u
git reset -- file
# show changes of a given changeset
hg diff -c rev
git diff rev~ rev
hg rebase Este metodo ramifica desde una rama origen y los commits pasan a ser de la NUEVA rama destino (faltaria probar que pasa con una rama existente). Curiosamente mantiene los SHA.
git checkout -b newbranch # switch to a new branchgit branch -f master HEAD~3 # make master point to some older commit
hg rebase mover una rama completa sobre otra, y luego hacer un merge (lo del merge no esta tan claro)
git checkout originBranch
git rebase destBranch
git checkout destBranch
git merge originBranch
(opcion B)
hg rebase
git checkout
# Bring the commits here
git merge
git checkout
# Move back by N commits.
git reset --keep HEAD~
git checkout
The --keep option preserves any uncommitted changes that you might have in unrelated files, or aborts if those changes would have to be overwritten -- similarly to what git checkout does. If it aborts, git stash your changes and retry, or use --hard to lose the changes
( solo 1 commit )
hg rebase -d -b
# CUIDADO, NO ACABA DE FUNCIONAR BIEN
git rebase --onto ~1
# quitamos los commits de la rama src
git co src
git reset --hard src@{2}
# ojo: rebase mantiene la rama, solo cambia la base.
hg revert fichero (local) git checkout -- fichero
hg revert fichero -r git checkout fichero
hg revert (local) git checkout
hg revert (staged) git reset
hg purge git clean -fd
hg revert --all git reset --hard
hg serve git daemon --reuseaddr --base-path=. --export-all --verbose --enable=receive-pack
hg log fichero git log -- fichero
hg graft git cherry-pick
hg commit --close-branch # delete local branch
git branch -d
# then
# delete remote branch (NB the colon)
git push origin :
# also
# remove remote tracking branches that no longer
exist
git fetch -p
hg log -b git reflog show
hg up -C git checkout -f
hg shelve git stash [push]
hg unshelve git stash pop
hg push --new-branch git push origin -u
git push --set-upstream origin
hg push -b git checkout <branch/feature> (opcional)
git push origin <branch/feature>
hg log -l git log -n
hg log -r git show --name-only
hg log --keyword git log --grep
hg blame -r git blame ^ --
git diff --exclude folder/file.h git diff -- . ":(exclude)folder/file.h"

Git configuration sample file with useful aliases ~/.gitconfig

[user]
	name = MY Full Name
	email = [email protected]
[core]
	editor = '/path/to/editor' -multiInst -nosession
	autocrlf = true
	pager = less --raw-control-chars

[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
[credential]
	helper = manager
[merge]
	tool = kdiff3
[diff]
	guitool = winmerge
[pull]
	rebase = false
[fetch]
	prune = false
[rebase]
	autoStash = false
[mergetool "kdiff3"]
	path = /path/to/kdiff3
[difftool "winmerge"]
	path = /path/to/WinMerge/winmergeu
	cmd = /path/to/WinMerge/winmergeu -e -u \"$LOCAL\" \"$REMOTE\"
[alias]
	ci = commit
	st = status
	co = checkout
	br = branch
	bra = branch -a
	ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%C(cyan)	\\ [%cn]" --decorate
	ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%C(cyan)\\ [%cn]" --decorate --numstat
	glog = log --graph --all --decorate
	glog2 = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%ae>%Creset' --abbrev-commit
	diffs = diff --staged
    	unstage = reset --soft HEAD^
	rollback = reset HEAD~
	purge = clean -fd
	alias = ! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
	out = !git fetch && git log FETCH_HEAD..
	in = !git fetch && git log ..FETCH_HEAD
Clone this wiki locally