Birdman
Birdman

Reputation: 1524

Git ignore not ignoring directories

I'm trying to ignore obj, bin, debug type files/directories from my Visual studio project. I've followed the advice here:

ignoring any 'bin' directory on a git project

This is not working.

I've pasted the entire git ignore here:

https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

This is not working.

I've tried all sorts of things...

bin/
obj/
*bin/
*obj/
/bin/
/obj/
packages
MyProject/MyProject/obj/
MyProject/MyProject/bin/Debug/
MyProject/MyProject/obj/*
MyProject/MyProject/bin/Debug/*

The directories and their files are still being included when I run a git add. The .gitignore file is added and commited. What am I doing wrong???

EDIT: The files I'm trying to ignore aren't already being tracked. When I run a "git status" there are no pending changes. "nothing to commit, working tree clean". Then I run my VS program which modifies the files in those folders. Then I run another git status and all of the files show up as "modified"...

EDIT2: Does it matter if the files already exist? They are not being tracked but DO exist in the folder structure. When when I run the program they show up again as "modified". Then I have to run a "git checkout ." to remove them all. Then the cycle repeats...

Upvotes: 2

Views: 843

Answers (3)

ATrimeloni
ATrimeloni

Reputation: 69

Based on your "Edit 2" above, it sounds like you don't think these have been previously committed, but in reality, they have been. If it shows up as "modified", the git is recognizing the file has changed from the last version it has checked in. If the file was not already committed previously then it would show up as Untracked.

When you are running git checkout on those files, you are telling git to revert those files back to the last version that was checked into git.

Upvotes: 0

Poorvi Nigotiya
Poorvi Nigotiya

Reputation: 458

If your file was already been tracked and committed before adding in .gitignore, it won't ignore it. You would require to remove it from index to stop tracking

For file

git rm --cached <file need to remove>

For Folders

git rm -r --cached <folder>

So that would be an issue in your case since Jenkins is still able to see the file in the repo

Upvotes: 5

Srinivasan Sekar
Srinivasan Sekar

Reputation: 2119

Hi look at the edit part ,

If you already have any folders in your git index which you no longer wish to track then you need to remove them explicitly. Git won't stop tracking paths that are already being tracked just because they now match a new .gitignore pattern. Execute a folder remove (rm) from index only (--cached) recursivelly (-r).

git rm -r --cached yourfolder

Upvotes: 1

Related Questions