2

I’m trying to convert ignore files between these DVCS formats. I know this question has asked before, but it’s been some time and the reported answer appears to be outdated. As noted in one of the responses “with git version 1.8.3.4 it does not work for every valid .hgignore”

Mercurial uses syntax to select the type of matching to use:

syntax: regexp    #Regular expression, Python/Perl 

or

syntax: glob      #Shell-style glob.

What syntax does git use? I’ve read it uses glob, but I’m not 100% sure it’s the same thing. If I specified glob for my mercurial ignore file, will that be 100% compatible with git? (Ignoring the syntax declaration line)

WhiskerBiscuit
  • 4,795
  • 8
  • 62
  • 100
  • Possible duplicate of [Interconversion of gitignore and hgignore?](https://stackoverflow.com/questions/4349043/interconversion-of-gitignore-and-hgignore) – StayOnTarget May 01 '19 at 11:25
  • The decade-old question's answer is still valid. The comments below that answer don't have enough detail to figure out what the person making a complaint about differences in glob syntax is talking about, but it's true that six-year-old versions of Git don't handle modern `**` the same way that modern ones do: `**/` was added in Git 1.8.3, and had a fix to it in 1.8.4. (Git 1.8.2 is dated March 2013.) – torek May 03 '19 at 15:50

2 Answers2

1

Yes, this was asked 10 years ago, and highlighted the fact that:

You might convert a glob pattern to a regex (also done here in ruby, or described in this article).
But you cannot convert all regexes as glob pattern.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

As @VonC states above, it's not possible to convert completely accurately.

However I've written a pretty basic .hgignore to .gitignore converter at https://github.com/devzendo/hgignore-to-gitignore

It tries to convert the elements of regexes that can be converted to glob elements, and passes glob elements as is (since hg seems to have a simpler form of glob than git, I'm assuming git can handle hg's globs).

Matt Gumbley
  • 307
  • 2
  • 8