12

I have a git repo that I need to get working without conflicts. It is .net/c# mvc repo. The problem is dll and pdb files. These files have been accidentally committed to the repo so when I do my initial git pull, I get all these files committed by another developer.

I have setup the .gitignore like so:

bin/
obj/
App_data/

From other posts I believe that is all I should need to do, however, If I build my project and run git status it shows numerous dll and pdb files that are going to be committed.

Is this because those files existed in the repo when I cloned it? If so, what is the best way to go about removing those files?

jalf
  • 243,077
  • 51
  • 345
  • 550
Mike McCoy
  • 797
  • 2
  • 10
  • 19
  • *why* are these files in the repository? You usually wouldn't commit that type of files – jalf Aug 26 '12 at 20:45
  • 1
    they were committed by another developer by mistake, as detailed in the question. I understand that those files wouldn't usually be committed. Hence, the question about how to go about removing them. – Mike McCoy Aug 26 '12 at 20:56
  • No, that's what confused me. Your question, the one you actually **asked** is about how to ignore changes to the files. You should edit the question to match what you actually want to know: that is, *how to get remove files that were accidentally committed* – jalf Aug 27 '12 at 09:05
  • @jalf noted and changed. – Mike McCoy Aug 27 '12 at 14:00

3 Answers3

12

You need to remove those file first (git rm), before seeing your .gitignore directoves applied to your git repo.

You can remove those files only from the index if you want to keep them on the working tree.

git rm -r --cached a.dll

(See ".gitignore file not ignoring")

But for generated files, it shouldn't matter if they are removed: you will re-create them at the next compilation, but ignore them because they aren't part of the index anymore.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok, just to be sure that I am clear. I run the above command and it will remove **ALL** dll files from the index, even those that may be references and not specifically build files. However, with my index cleared of those files my `gitignore` file should function correctly and references dll's will be added back, but dll's in my `bin` and other directories should be ignored, correct? – Mike McCoy Aug 26 '12 at 20:51
  • @MikeMcCoy Yes, `git rm *.dll`: see http://stackoverflow.com/questions/9529354/git-rm-several-files. That will remove them from the disk and from the git index. But if those files were already deleted from vthe working tree (ie, the disk), then consider http://stackoverflow.com/questions/636013/unable-to-remove-fast-many-files-in-git – VonC Aug 26 '12 at 20:58
  • @MikeMcCoy regarding your second part of your comment, if you `git rm` too much, then yes, all the non-ignored dll will be added back, and the other, since they are no longer part of the index, will be ignored. – VonC Aug 26 '12 at 20:59
1

This is very common question and the usual answer is that you cannot clean up past commits, but there are special tools for this . git filter and easier the BFG repo cleaner: http://rtyley.github.io/bfg-repo-cleaner/#usage

Gregor
  • 358
  • 2
  • 7
0

Your .gitignore File has a mistake. It should be like this:

bin
obj
App_data
Dharman
  • 30,962
  • 25
  • 85
  • 135
Darren G
  • 193
  • 2
  • 9