Solve Git problem to avoid storing filenames/paths having backslash chars, which are invalid in Windows

60 Views Asked by At

I would like to solve Git problem to avoid storing filenames/paths having backslash chars, which are invalid in Windows, like /etc/systemd/system/snap-git\x2dfilter\x2drepo-7.mount.

I should add a specific string to .gitignore to avoid storing filenames/paths mentioned above.

I tried in .gitignore

/*\*/
snap-git

But the snap-git\x2dfilter\x2drepo-7.mount file was still added to the Git repo.

What would be the right regular expression to exclude these invalid files from Git repo?

I don't have idea why the /*\*/ and snap-git does not work in .gitignore.

What I do wrong? Maybe .gitignore does not match the full path, just the filename itself? This is the point I'm wrong?

EDIT1: I found the following info in .gitignore doc:

Two consecutive asterisks ("**") in patterns matched against full pathname 
may have special meaning:

A trailing "/**" matches everything inside. For example, "abc/**" 
matches all files inside directory "abc", relative to the location of 
the .gitignore file, with infinite depth.

So instead of snap-git pattern, I have to use trailing "/**" to match all files inside directory snap-git:

snap-git/**
0

There are 0 best solutions below