0

I wanted to ignore the entire .vs folder because I was getting a locked/permission denied error on sqlite3/db.lock found in the .vs folder, so I created a .gitignore file with this bash command:

touch .gitignore

and then added this line inside of the .gitignore file:

.vs/*

But I still got the same error when I run git add --all.

In the end, I opened Sourcetree app, ignored the .vs folder content by right clicking the files and choosing ignore, and then I managed to add all the files, commit and push (through the Sourcetree app).

Not pleased with this solution because I wanted to do everything through command line. Now I am wondering why has the gitignore content not changed if I supposedly have manipulated it through Sourcetree? And how can I add files to .gitignore? What I did didn't seem to have any effect (the fact that I added line .vs/*)

1 Answer 1

1

What you did had an effect. Namely that all future changes will be ignored.

The issue here is that when you add files to .gitignore they will be ignored from any changes you make but they will still remain in the repository. What you need to do is remove everything from git and add them again. This way the files you want ignored won't be added.

You can do this with the following commands:

git rm -r --cached .
git add .
git commit -m ".gitignore fix"

Reference: http://www.codeblocq.com/2016/01/Untrack-files-already-added-to-git-repository-based-on-gitignore/

8
  • That's great, thanks you! I thought I had tried that before but maybe not in the right order. So the commit finally got pushed and all well but ... except for the few (about 4) files I have changed, actually no less than 37 files got pushed to the server (a number of cache, pdb, dll, xaml files, basically everything from bin/Debug and obj/Debug). Shouldn't these files be ignored at commit? The point of having various commits was to observe the few required/relevant changes matching some (sometimes) minor requests... if I examine my last commit I get lost in all the debug files
    – Sami
    Jun 24, 2019 at 14:01
  • Add all the debug paths to gitignore one by one manually would be far from ideal (I have many projects). PS. I already tried adding two lines bin and obj to .gitignore - it doesn't help.
    – Sami
    Jun 24, 2019 at 14:49
  • Yeah I'm not familiar with some of the tools you are using but it seems like those files should be ignored. If you added it to the .gitignore after adding the files and then followed the instructions I gave the files will still be in the commit history so some commits will contain them. However, the latest commit wouldn't have them. Are you sure you added them to the .gitginore properly? If so please update your question and list the files you wanted ignored (full path from project root) and the relevant .gitignore entries. If it's an open source project I could look at the repo for you?
    – KNejad
    Jun 24, 2019 at 14:52
  • This is my .gitignore content, just 3 lines: .vs/* on one line, bin on the next and obj on the last. ShopViewer.View/bin/Debug/ShopViewer.Presentation.dll is one of the 37 files that got into the commit, even though bin was added to .gitignore, but maybe I didn't add it correctly. I'm still researching a better way to do it. Thank you.
    – Sami
    Jun 24, 2019 at 15:07
  • Hm that's strange. That should be working. Editing anything in ShopViewer.View/bin/ shouldn't cause git to add the changes. Sorry not sure what's going on
    – KNejad
    Jun 24, 2019 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .