Skip to content

Instantly share code, notes, and snippets.

@kbilsted

kbilsted/hg2git.md

Last active May 2, 2020
Embed
What would you like to do?
Git guide for Hg users

A Git guide for Hg/Mercurial users

Delete stuff

  • hg uncommit / hg strip
  • git reset --hard HEAD~1

Combine stuff

  • hg combine xx (from xx to yy)
  • git reset --soft HEAD~3
  • git commit or
  • git rebase -i head~3

Rewrite history

  • git rebase -i HEAD~11

Move branch pointer

  • git branch -f branch-name new-tip-commit

Fetching stuff

  • hg pull
  • git fetch
  • hg pull + rebase
  • git pull

Fetch from upstream

(first time only)
git remote add upstream /url/to/original/repo 

git fetch upstream
git checkout master
git reset --hard upstream/master  

(when no changes on origin)
git push origin master --force

(when changes on origin)
git merge upstream/master

Deleting a branch locally and pushing delete up

git push origin --delete <branch>
git branch --delete <branch>

Deleting a local remote-tracking branch:

git fetch origin --prune

Merging PR on branch addMapToProjector onto new branch feature/foo from user janus project stateprinter

git checkout -b feature/foo master
git pull https://github.com/janus/stateprinter.git addMapToProjector
git push -u  "origin" refs/heads/feature/foo:refs/heads/feature/foo

nice Powershell functions

function unco()
{
	"git reset --soft head~1"
	git reset --soft head~1
}
function bundle($path)
{
	"git format-patch origin/master --stdout > c:\bundle\$path.diff"
	git format-patch origin/master --stdout > c:\bundle\$path.diff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.