1

In our small team we currently use Mercurial hg for a few projects. We talked about trying to move to Git. I thought about adding Git to the parent directory, to allow a more gradual transition. I'll be the first one to make this move - I'll use mostly Git for most of the tasks, but I'll pull and push from Mercurial hg.

This obviously requires that each version control ignores the files of the other. I'd like to confirm that this is doable, and that there is no known conflict for running Mercurial hg and git together.

Update

If I use mostly Git, and use Mercurial only for the final step - committing and pushing from Master to the remote repository - what are the risks?

Ben Carp
  • 24,214
  • 9
  • 60
  • 72
  • Yes, it's possible. But it's unnecessary for most cases, since you need to do additional work to manage the same thing into two version control systems. Instead, the common way is migrating hg to git. – Marina Liu Jul 05 '18 at 07:24
  • This question is quite specific, so though I don't think its quite literally a dupe this other question covers much of the same ground: https://stackoverflow.com/questions/883452/git-interoperability-with-a-mercurial-repository – StayOnTarget Jul 05 '18 at 11:11
  • @MarinaLiu-MSFT, Migrating seems like the right step, but not everyone are ready for it. Please take a look at my update and let me know what u think. – Ben Carp Jul 08 '18 at 07:25
  • @Ben So there has no risks to use both. And I added answer with different situations, you can choose the situation you need. – Marina Liu Jul 09 '18 at 09:02
  • @Ben Have you get the answer which helps you solve the problem? If yes, can you mark the answer by clicking √ symbol on the left of the answer? And it will also benefit other members who meet similar questions. – Marina Liu Jul 16 '18 at 09:03

3 Answers3

1

You could use git-remote-hg, which:

is the semi-official Mercurial bridge from Git project, once installed, it allows you to clone, fetch and push to and from Mercurial repositories as if they were Git ones

The idea would be to clone from HG to git (using git-remote-hg to enable this). Then you can work in git all you want but ultimately still share work with others via HG push/pull.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
0

You can do this (I did a variant of this at a previous $workplace, when I got fed up with Mercurial's slowness and lack of flexibility with respect to history editing). Add .hg to the .gitignore and .git to the .hgignore files. I would advise against it, though: it is painful, and requires that you know a lot about the internals of both VCSes.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks! If I use mostly Git, and use Mercurial only for the final step - committing and pushing from Master to the remote repository - what are the risks? would it still be painful? Why? – Ben Carp Jul 08 '18 at 07:27
  • If you are the *only* one making commits, and you use this method, it should be much easier. What gets difficult is re-synchronizing the repositories when other people make commits. – torek Jul 08 '18 at 12:07
  • Not really, no. The project was proprietary and I don't really want to (or have time to) go construct artificial examples. – torek Jul 09 '18 at 18:37
0

If it’s not already for you to migrate hg repo to git repo, you can use both git and mercurial for the temporary period. And there has no risks to do that.

The only thing need to be noticed is what's the situation (list below) for you to use git:

  • Situation 1: manage hg repo including all the versions into git repo

    If you want to both manage the file versions and hg repo versions in git repo, you just commit all the files (including files in .hg folder) of the hg repo into git repo.

  • Situation 2: only manage the files into git repo (no information about hg repo will be recorded in git repo)

    If you only want to manage the file versions into git repo, then you need to ignore hg repo’s information by adding .hg folder into .gitignore file (as torek mentioned).

And when you are ready to migrate hg repo to git, then keep the migrated git repo for version control.

Community
  • 1
  • 1
Marina Liu
  • 36,876
  • 5
  • 61
  • 74