4

I used to develop on linux environment, but now I need to write a git project on "windows" os. I need to ignore a directory from where the git is initiated.

like folder/.git/, now I need to ignore /folder/project/bin/*. So I have added .gitignore file on folder/.gitignore using both text pad and Visual studio.

.gitignore file contents are

/project/bin/*

Now, I expect git status should not show /project/bin folder.

Note, I have tried other ways too, but it seems that git is considering the .gitignore file as a general text file or so.

Sumsuddin Shojib
  • 3,583
  • 3
  • 26
  • 45

2 Answers2

2

Just a guess, but I suspect that the leading forward-slash is throwing something off. I'm not sure about the trailing star either (as I reference my own .gitignore files).

Your .gitignore should be this:

project/bin/
selbie
  • 100,020
  • 15
  • 103
  • 173
  • Tried that too. I have found some says about the .gitignore file's font encoding issue(Unicode is not supported). I don't have a clear idea about that. Thanks. – Sumsuddin Shojib Nov 10 '15 at 06:47
  • 7
    Open the .gitignore with Windows Notepad and select `File->Save As`. The bottom of the file-save dialog will have an Encoding box. Select **ANSI**. – selbie Nov 10 '15 at 06:48
  • @selbie - In my case "*" was not working, your comment was the actual answer for me. – Niroshan Aug 20 '18 at 00:24
  • @selbie's solution was the only one worked for me, thanks! – Tomer Gal Oct 30 '20 at 07:33
0

I frustratingly found the same issue. I couldn't seem to ignore folders, but files were OK. My issue started with folders that contain spaces. All the combinations I could find after a searching (full directory path, trying to ignore case, escaping the spaces, etc) didn't resolve it.

I had to remove spaces in directory names, then I was able to ignore files. I tried it on WSL (Windows sub-system for Linux - git was already installed), no problems.

Then reading more, I realised that if files are previously tracked, then the .gitignore won't work. I tested it by deleting all the files in the directory, then adding the directory to .gitignore path/to/my_files/*.csv (in my case I'm ignoring data in .csv files) and doing a commit then push (good job this is just dev).

After that worked, I was able to use git rm -r --cached ./path/to/my_files/ to un track all the files in another directory rather than cutting and pasting them back (Thanks to this answer)

So:

  1. Un-track all the files
  2. Add the directory in .gitignore (In windows it wasn't case sensitive)
  3. add/commit/push as normal.
Coffee and Code
  • 885
  • 14
  • 16