36

I want to do simple thing, ignore .suo file and bin and obj folders from committing to git repo. I've created .gitignore file and it's working for bin and obj folders, but it keeps allowing .suo file committing. The content of gitignore is simple:

/build/
*.suo
*.user
_ReSharper.*/
*.sdf
bin/
obj/
Debug/
Release/
*.opensdf
*.tlog
*.log
TestResult.xml
*.VisualState.xml
Version.cs
Version.h
Version.cpp

Firstly I've thought that the problem is that .suo file is already on the repo, so I've used set of git commands to remove it from repo:

git rm "file.suo"
git commit -m "suo removed"
git pull origin master
git push origin master

And everything goes well, .suo is removed locally, it is removed from repo, and on the next commit it gets pushed again to repo.

On the picture is committed .suo file.

enter image description here

Did anyone had a problem like this? How to solve this kind of problem?

nemo_87
  • 4,523
  • 16
  • 56
  • 102
  • 1
    Did you pay attention to what `git status` tells you? – Jonathon Reinhart Feb 27 '15 at 07:41
  • possible duplicate of [gitignore all files of extension in directory](http://stackoverflow.com/questions/10712555/gitignore-all-files-of-extension-in-directory) – nwinkler Feb 27 '15 at 07:42
  • 3
    It looks like you want to use the _**/*.suo_ pattern to ignore files like this in all directories. The pattern you have used only applies to the project root. – nwinkler Feb 27 '15 at 07:43
  • 3
    "*on the next commit it gets pushed*" No. Firstly, nothing gets pushed when you commit. Secondly, nothing gets commited unless it has been explicitly added. – Biffen Feb 27 '15 at 07:45
  • 2
    @nwinkler No this syntax is supposed to ignore all files anywhere in the tree matching that pattern. –  Feb 27 '15 at 07:53
  • @nwinkler what is the best place to put .gitignore? Should it be in git folder or somewhere else? – nemo_87 Feb 27 '15 at 07:53
  • You can add `.gitignore` files anywhere in your repo. Either in the root, and use patterns like I mentioned above, or in each individual directory in your repo. You can also use both - one in the root for general exclusions, and then individual ones per directory. Make sure you add and commit the `.gitignore` files as well. – nwinkler Feb 27 '15 at 07:55
  • 1
    Place the `.gitignore` in the directory that **contains** the `.git` directory in order to apply it to all your sources below that path. Use https://www.gitignore.io to create a `.gitignore`. – eckes Feb 27 '15 at 07:55
  • The following answer might help: http://stackoverflow.com/a/11629271/4371525 – Shy Agam Jun 12 '16 at 21:29
  • Possible duplicate of [GIT - Can't ignore .suo file](http://stackoverflow.com/questions/11628418/git-cant-ignore-suo-file) – Jesper Rønn-Jensen May 04 '17 at 13:57

2 Answers2

56

This is probably a duplicate of GIT - Can't ignore .suo file

And to be honest, you can try that suggestion. What you are missing here is to remove the already added *.suo file from the git repository.

The other answer has a nice set of commands to run:

git rm --cached *.suo
git commit -m "Delete suo file from repository"
Community
  • 1
  • 1
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
0

Jsper answered correct. He already explained why this usually happens. But I got another probably easy solution without command line & gui lover devs. What I simply do is:

  1. First delete the directory or file from your github/dev ops repository from web gui
  2. Then simply sync your project locally first then you are ready to make new commit without your annoying autogenerated file or directory.
Liakat Hossain
  • 1,288
  • 1
  • 13
  • 24