0

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/**
klor
  • 1,237
  • 4
  • 12
  • 37
  • I'm guessing you need a line with `*\\*`. LMK if that works and I can make it an answer. – TTT Jul 05 '23 at 16:20
  • Note that `.gitignore` only works on untracked files, so if any of the files are already committed and currently tracked, then modifications to those file will still show up as changes, regardless of `.gitignore` entries. In that case you'll need to delete the files, and commit that deletion, so that `.gitignore` will prevent them from getting added from then on. – TTT Jul 05 '23 at 19:47
  • @TTT Thank you very much for the ideas. I will test the suggestion tomorrow. – klor Jul 05 '23 at 22:19
  • I don't have idea why the `/*\*/` and `snap-git` does not work in .gitignore. What I did wrong? – klor Jul 05 '23 at 22:22
  • Did you try my suggestion? My assumption is `/*\*/` didn't work because you need two slashes instead of one. (You must escape the backslash with another backslash.) Also the trailing `/` signifies a directory instead of a file. The reason `snap-git` doesn't work is because you don't have a file or directory named "snap-git". The reason `snap-git/**` doesn't work is also because you don't have a directory named "snap-git". BTW, I'm guessing `snap-git*` would have worked. – TTT Jul 07 '23 at 16:02
  • I added, but it's rarely reproduced by the system. Can I reproduce it manually? – klor Jul 07 '23 at 20:14
  • Create a file with the backslash character in it and see if it ignores it? – TTT Jul 07 '23 at 21:07

0 Answers0