Skip to content

Instantly share code, notes, and snippets.

@amirnissim
Created May 12, 2014 09:02
Show Gist options
  • Save amirnissim/d8bfc8c27f6e5df1429a to your computer and use it in GitHub Desktop.
Save amirnissim/d8bfc8c27f6e5df1429a to your computer and use it in GitHub Desktop.
# this file documents the process I used to migrate the project from
# mercurial (bitbucket) to git (github)
#
# we are going to need
# - fast export: https://github.com/frej/fast-export
# - bfg: http://rtyley.github.io/bfg-repo-cleaner/
alias bfg="java -jar bfg.jar"
# clone single revision of the hg repo to eliminate unwanted heads
# (otherwise git export will fail)
hg clone <hg://repo-url> repo.hg --rev 2418
# remove all .git directories
find . -type d -name .git | hg rm
hg commit -m '.git cleanup'
# create an authors file and edit if needed
hg log --template "{author}\n" | sort | uniq -c > authors.map
# export to git
cd repo.git && git init
fast-export/hg-fast-export.sh -r repo.hg -A authors.map
# clean history of all .git directories
bfg --delete-folders .git --no-blob-protection repo.git
# -- REMOVE SENSITIVE INFORMATION FROM YOUR FILES -- #
# create a patch with the sensitive data to be restored it in the future
# sensitive files will be completely removed from the project history.
# there will be no other way to restore it.
# KEEP THIS FILE IN A SAFE PLACE!
git diff HEAD~1 > sensitive-data.patch
# commit
git commit -am 'removed sensitive information'
# clean history for sensitive files
git diff --name-only HEAD~1 | xargs -0 -I {} bfg --delete-files {} repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment