12

I have been working on a POC and now have been asked to upload it to our GitHub. I have done that, but today I notice the bin and obj folder being included.

So I opened up my .gitignore file to check I've added the Visual Studio profile. Which it was.. I could see [Bb]in/ and [Oo]bj/ are included.

So I tried to remove the folder from Git by typing:

git rm --cached -r [folder]/bin

After doing that I saw all the *dll being removed, I checked in Team Explorer and noted that the files were all removed.

Committed, and rebuilt to see that all the bin files returned...

it's not just one project in the solution. It seems to be all of them doing this. I have my .gitignore file in the root of my solution. As well as the .git folder. Screen shot of folder structure.

  • I tried copying the .gitignore file to the project folder. didn't work
  • I tried adding **/[Bb]in/ & **[Bb]in/ .. no change.

Any ideas on what I'm missing here?

My .gitignore is an exact copy of this here

I reverted my **/[Bb]in/ changes to see if I broke something.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Anthony
  • 287
  • 1
  • 2
  • 10

3 Answers3

23

git ignore ignore the file that hadn't been tracked yet, so if a file was committed it will reappear again.

you can try:

git rm -r --cached . 
git add .

then

git commit -am "Remove ignored files"

as suggested here

or go for a more radical approach:

  • remove the files with rm
  • then reset the .git directory (remove it, then initialize it anew with git init)
  • create a new remote branch
  • push to the new branch
  • if all looks ok, then merge with the mean branch.
Community
  • 1
  • 1
yaitloutou
  • 1,691
  • 19
  • 23
  • 1
    Thanks. Yeah this first option failed on me at first. I decided to restart my machine after noticing tortoiseGit started asking me for my password again randomly. I tried it again, and it worked. So maybe there was some caching interfering .. not to sure.. Thankfully I didn't need to do the radical approach. – Anthony Jan 12 '17 at 02:22
  • some times git ignores gitignore, and it's really annoying, glade that worked out for you :) – yaitloutou Jan 12 '17 at 02:28
  • Perfect solution, can't believe the other threads with hundreds of upvotes didn't help me further but this one did – csstudent1418 Sep 05 '20 at 16:06
  • This is so silly.. why is rider a paid product behaving this way is beyond my understanding.... – user1034912 Oct 04 '21 at 04:16
0

If you have already commited something which you now want to ignore, you have to tell git to remove those files from its index with git rm --cached <files>

You also need to make sure you have the below in your .gitignore file:

bin/    # ignore bin directory
*.obj   # ignore any files with .obj postfix

Add your commit:

 Ignore bin/ directory and any *.obj files
Rami Zebian
  • 539
  • 1
  • 5
  • 23
0

In my case, even deleting the .git and creating a new repository, he did not ignore it. The problem was in my .gitignore, it is in utf16, I moved to utf8 problem solved!