111

I'm trying to work using Git with a colleague, in an application written in C#.

We have added the entry "project1.suo" to the .gitignore file but every time one of us has to commit the project, Git seems to tell us to commit the file "project1.suo" as well.

We have tried many methods to add the file in .gitignore like that:

*.suo
project1.suo
c:\project\project1.suo

We cannot fix this problem.

Valentin Sky
  • 132
  • 1
  • 9
Laxedur
  • 1,185
  • 3
  • 9
  • 8

3 Answers3

211

git doesn't ignore files that have been added to the repository. If you want to get it ignored, you have to delete the file from the repository:

git rm --cached project1.suo
git commit -m "Delete suo file from repository"

This will delete the file from the repository, while it's still on your harddrive.

Ikke
  • 99,403
  • 23
  • 97
  • 120
  • if you rm the *.suo files, certainly it's not going to push those files remotely. Will it cause the problem for the person who clone this project? – Waqas Feb 19 '16 at 12:54
  • If you're using the visual studio client, there is no way to do this from there, you have to use the cmd shell. But if I used the rm command from the shell, I would see the .suo file with a strikethrough, but if I committed the change through the VS UI, it would reappear. You have to do both commands above through the command-line. – Michael Blackburn Apr 04 '16 at 18:25
  • 1
    @Waqas no, visual studio will just create a new file for them. This is when the .gitignore excluding *.suo as part of the repository is important. When they commit, the .gitignore they checked out will prevent them (or at least discourage them) from checking in their own SUO file. – Michael Blackburn Apr 04 '16 at 18:27
  • 6
    This might not be obvious for some new folks. This worked like a charm. To execute this command, you must be inside the folder where the .suo is located. First command you need to run in cmd.exe is change directory "CD then press enter.. By default you might not see the .vs folder where the .suo is so make sure show hidden files is enabled in your repository folder root. My file did not have a project name. just the extension. git rm --cached .suo git commit -m "Delete suo file from repository" – moto_geek Jul 07 '17 at 16:48
  • if need to ignore folder, and it is already in remote repo. use -r option in command, git rm -r --cached – Somnath Kadam Jan 29 '20 at 13:13
  • I deleted the .suo file via Web interface of the TFS git for the project and it worked that way. – AntiqTech Mar 14 '22 at 10:31
5

I always back to this question to use the method in the answer but i found a better solution which is to ignore the changes to this file . The method is

git update-index --assume-unchanged project1.suo

or

git update-index --assume-unchanged .vs/config/applicationhost.config

To undo this use --no-assume-unchanged

Tareq
  • 1,397
  • 27
  • 28
  • I receive a message "fatal: Unable to mark file Web /" – dancerjude Mar 07 '18 at 15:01
  • Note that this will lead to issues when someone does update the file. Git will try to update the file, but notices it has changed and will give you an error message. In any case, `--skip-worktree` is better than `--assume-unchanged`, which should only be used for performance reasons. – Ikke Feb 13 '20 at 08:49
-4

I had the same problem. Ikke's solution helps, but do not forget to remove the *.suo entry from your .gitignore, if it is there. After the file is corrected, do

git add **/*.suo
olegtaranenko
  • 3,722
  • 3
  • 26
  • 33