Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore and Visual Studio project: Ignore bin/Debug directory but not bin/Release directory

I have a C# Visual Studio project in a git repository. I want to ignore the contents bin/Debug directory but not the contents of the bin/Release' directory. I've added bin/Debug to my .gitignore file, but it doesn't seem to work - it is including the entire contents of the bin directory. What would the correct entry be to do this?

like image 434
Dan Stevens Avatar asked Jun 20 '12 15:06

Dan Stevens


People also ask

How do I ignore an OBJ debug file in Git?

Right click on those file names you want to ignore from "Git Desktop", then add them to . gitignore file. Here gitignore file will be automatically created. Check in that file to git.

How do I Gitignore a folder in Visual Studio?

Open Visual Studio and the solution needing an ignore file. From the top menu select Git > Settings. The above will open Visual Studio's Options with Source Control > Git Global Settings selected. From the list on the left select Git Repository Settings and then click the Add button for Ignore file.

How do I ignore files in Visual Studio?

Visual Studio GitIn the Git Changes window, right-click any changed file that you want Git to ignore and choose Ignore this local item or Ignore this extension.


2 Answers

You shouldn't have to delete anything. After you added the .gitignore file, run this command to clear the cache, then stage and commit again:

git rm -r . --cached 
like image 108
orourkedd Avatar answered Sep 19 '22 15:09

orourkedd


This typically happens because the .gitignore was added after the files were committed. The .gitignore tells git to ignore untracked files that match, once stuff is committed the ignore will no longer work. One way to fix it is to remove the bin/debug folder (manually through explorer/powershell/bash), then commit the removals. Once that is done the ignores should work as you expect.

  1. Remove files/folder
  2. git add -A
  3. git commit
like image 33
Gary.S Avatar answered Sep 16 '22 15:09

Gary.S