How To Convert A Mercurial Repository To Git On Windows
There are various guides on the internet to converting a Mercurial repository into a git one, but I found that they tended to assume you had certain things installed that might not be there on a Windows PC. So here’s how I did it, with TortoiseHg installed for Mercurial, and using the version of git that comes with GitHub for Windows. (both hg and git need to be in your path to run the commands shown here).
Step 1 – Clone hg-git
hg-git is a Mercurial extension. This seems to be the official repository. Clone it locally:
hg clone https://bitbucket.org/durin42/hg-gitStep 2 - Add hg-git as an extension
You now need to add hg-git as a mercurial extension. This can either be done by editing the mercurial.ini file that TortoiseHg puts in your user folder, or just enable it for this one repository, by editing (or creating) the hgrc file in the .hg folder and adding the following configuration
[extensions] hggit = c:/users/mark/code/temp/hg-git/hggitStep 3 – Create a bare git repo to convert into
You now need a git repository to convert into. If you already have one created on GitHub or BitBucket, then this step is unnecessary. But if you want to push to a local git repository, then it needs to be a “bare” repo, or you’ll get this error: abort: git remote error: refs/heads/master failed to update. Here’s how you make a bare git repository:
git init --bare git_repoStep 4 – Push to Git from Mercurial
Navigate to the mercurial repository you wish to convert. The hg-git documentation says you need to run the following one-time configuration:
hg bookmarks hgAnd having done that, you can now push to your git repository, with the following simple command:
hg push path\to\git_repoYou should see that all your commits have been pushed to git, and you can navigate into the bare repository folder and do a git log to make sure it worked.
Step 5 – Get a non-bare git repository
If you followed step 3 and converted into a bare repository, you might want to convert to a regular git repository. Do that by cloning it again:
git clone git_bare_repo git_regular_repo TweetComments
June 29. 2019 12:14 The git repository needs a hint which branch to use, I found help at https://stackoverflow.com/questions/10710250/converting-mercurial-folder-to-a-git-repository/31827990#31827990, that uses not a bare repository and at the end does a checkout to get the hg tag to the master branch.
Patrick
January 15. 2020 22:34 This is the first result for "mercurial to git migation" query... but it doesn't work as is...I find this thing frustrating for developers needing a fast way to do what they want...I found the way to do that and now i'm sharing my findings...Replace Step 4 first commad hg bookmarks hg with hg bookmark -r default masterThis solved for me the annoying "conversion fail" problem
Enrico Siboni
January 15. 2020 22:37 Thanks for sharing your solution. This post is 7 years old now, so not surprising it doesn't work anymore
Mark Heath
February 10. 2020 20:42 It does, really, just did it.
Remco
February 10. 2020 20:44 Thanks for the reference. This worked like a charm, for me at least.Did have some issues, but updating mercurial solved most of those.Also, knowing that master isn't the latest branch since it's renamed to hg does help.Glad I could finally convert without too much of an issue. Although i prefer hg over git when it's about comprehendability, git has become the default standard. Thanks again for this old, but useful post.
RemcoAbout Mark Heath
I'm a Microsoft MVP and software developer based in Southampton, England, currently working as a Software Architect for NICE Systems. I create courses for Pluralsight and am the author of several open source libraries. I currently specialize in architecting Azure based systems and audio programming. You can find me on:
Search this site
Keep Updated
Subscribe to our mailing listMy Pluralsight Courses
- Microservices: Architectural Strategies and Techniques
- Azure Functions Deep Dive
- Microservices Fundamentals
- Refactor and Optimize Code with GitHub Copilot
- LINQ Best Practices
- Microsoft Azure Developer: Deploying and Managing Containers
- Azure Functions Fundamentals
- Azure Durable Functions Fundamentals
- Microservices Architecture: Executive Briefing
- Building Microservices
- Dapr 1 Fundamentals
- Create Serverless Functions
- More Effective LINQ
- Versioning and Evolving Microservices in ASP.NET Core
- Microsoft Azure Developer: Implement Azure Functions (AZ-204)
- Azure Container Instances: Getting Started
- Building Serverless Applications in Azure
- Azure CLI: Getting Started
- Understanding and Eliminating Technical Debt
- Windows Forms Best Practices
- Digital Audio Fundamentals
- UWP Audio Fundamentals
- Audio Programming with NAudio
- Understanding Distributed Version Control Systems
- Creating Modern WPF Applications with MahApps.Metro
- Creating and Selling a Digital Product
- ClickOnce Deployment Fundamentals
My Open Source Software
- NAudio
- NLayer
- NAudio.SharpMediaFoundation
- WaveForm Renderer
- WPF WaveForm
- TypeScript Tetris
- Skype Voice Changer
- MIDI File Mapper
- MIDI File Splitter
- SilverNibbles
- Asterisk
- WPF Shapes
- .NET Voice Recorder
Archives
Tags
- Azure (160)
- NAudio (103)
- Advent of Code (82)
- LINQ (79)
- C# (71)
- F# (70)
- Azure Functions (69)
- Azure CLI (47)
- WPF (39)
- audio (38)
- XAML (38)
- JavaScript (36)
- Silverlight (34)
- Pluralsight (30)
- Durable Functions (26)
- Docker (26)
- MoreLINQ (26)
- Azure Blob Storage (21)
- Azure Service Bus (17)
- PowerShell (16)
Từ khóa » Hg 2 Git
-
Migrating To Git
-
Convert Mercurial Project To Git [duplicate] - Stack Overflow
-
Hg-Git Mercurial Plugin
-
Convert A Mercurial Repository To Git Using Hg-fast-export - DZone
-
Mercurial To Git Bridge, Pushed To Directly From The Hg-git Plugin In Hg
-
A Git-hg Utility For Checking Out And Tracking A Mercurial Repo. - GitHub
-
Hg-git - PyPI
-
What I Learnt Migrating To Git From Mercurial (updated June 2020)
-
Mercurial Vs. Git: How Are They Different? - Perforce Software
-
Mercurial SCM
-
Hg-git Package : Ubuntu - Launchpad
-
Migrating 140000 Commits From Mercurial To Git - Medium
-
PEP 512 – Migrating From To GitHub
-
How To Create Patch Series On Mercurial And Git - Redmine