0

I just started a new Visual Studio project that uses Git as source control. I needed to create a .gitignore file because all my *.dll and *.pdb files were showing up as modified files when I did 'git status'. Even after adding the .gitignore and adding *.dll and *.pdb in the file, the 'git status' command still showed the files.

I read somewhere in SO that all I needed to do is execute: git rm -r . --cached

But when I did that, 'git status' now shows all my .cs files as deleted!

What do I do now? In Visual Studio I see the deleted icon next to each .cs file but it also shows me the deleted files in the Staged section. Plus, it shows the .cs files as 'added' in the Changes tab.

Can someone explain this. I'm not a Git expert.

Thanks,

Ray
  • 4,679
  • 10
  • 46
  • 92
  • If you're not sure of the state of your repository you can wipe everything locally and download a older state from the remote. They way I like to think of the problem is 1) clean up ignore files and commit the changes. Since these are build artifacts it's safe to just delete them from the file system. 2) fix and commit .gitignore – Jasen May 18 '17 at 18:24
  • Then remember _you're very first commit should be .gitingore_. And you can [script this into init](http://stackoverflow.com/questions/16658087/automatically-add-gitignore-and-hooks-on-git-init). – Jasen May 18 '17 at 18:27

1 Answers1

0

If files show up as modified it's because the files were already part of the previous revision and so when you told git to remove them from cache, then they would be deleted in terms of how the new revision relates to the previous one. Adding the files to .gitignore will only work for files that git is not already tracking. So, if you allow the files to be "deleted" from the revision and commit, you will be good because they won't be added on revisions after the next... however if you move forward a few revisions and then decided to checkout one of these revisions that have those files, git will probably refuse to do it because it would overwrite the ones you had on the working tree.... which leads me into the following comment: you should get rid of those files on the revisions where they are already committed so that the files are not on the history of the branch.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • How do I get rid of the revisions where they are already committed so that the files are not in the history of the branch? – Ray May 18 '17 at 18:47
  • It's been a question that has been asked over and over. The simplest way is: - Checkout the last revision that is _good_ (it doesn't contain the files you want to get rid of). - Start cherry-picking the revisions where the files were added (modified) and amend them by removing the files you don't want. – eftshift0 May 18 '17 at 18:51
  • Also consider rewriting the history instead: http://stackoverflow.com/questions/16558782/git-how-to-delete-committed-file-permanently/16558879 – eftshift0 May 18 '17 at 18:53