I am using standard Visual Studio .gitignore file, but Git for Windows still includes build files and other stuff. How to fix this?
Git ignore file I am using: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore Visual Studio generates the same thing automatically
It is named correctly, and it is in the right place
When I enter git status command it shows build files
Check the file you're ignoring Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.
Open Visual Studio and the solution needing an ignore file. From the top menu select Git > Settings. The above will open Visual Studio's Options with Source Control > Git Global Settings selected. From the list on the left select Git Repository Settings and then click the Add button for Ignore file.
gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.
To stop tracking the files in the gitignore file;
Open a command prompt and navigate to the directory that contains your solution file (.sln), then run the following commands (first two commands contains dot at last):
git rm -r --cached .
git add .
git commit -am "Remove ignored files"
Then open your Visual Studio and sync your repo. That seemed to do the trick for me. I found the git commands here.
For us worked this approach:
The files are modified, meaning they were already in the git repository before you added the .gitignore file (or you added them explicitly) so you cannot 'ignore' changes to them anymore now.
If possible, just start over again and create the repository from scratch but now make a first commit which just adds the .gitignore file (which is always a good idea btw), then a second commit adding all source files; the build files will then be ignored.
Alternatively you could rewrite the history using interactive rebasing, by modifying the commit in which you add those files, and adding the .gitignore in an earlier commit would also not be bad. Or you could use branch filtering to get rid of all traces of those files. And there's probably other options.
It is possible to stop tracking any changes for any checked in file. You need to tell git to remove the file from its index first by calling the following in the given repository > git rm --cached <file>
. Then update your .gitignore
file to exclude the file. Finally commit the removal of the file.
Source from Microsoft Git guide.
This little trick helped me. It removes all files that have been cached as being 'tracked', then re-adds files based on the .gitignore file
remove (git rm) all files recursively (-r) that are cached as being tracked
git rm -r --cached .
Add all (git add .) files that have changed/aren't accounted for in the cache back; this will re-add the files as they were, so there won't be a need to 're-save' the files, they'll just disappear from git changes that would've removed the file (and all other files due to the first command)- result is that "changes" or git status should just have the files that are now going to be ignored by .gitignore if they were not before the .gitignore change.
git add .
https://sigalambigha.home.blog/2020/03/11/how-to-refresh-gitignore/
This was a long struggle for me, finally I have my dll's being quiet when I just want to merge my changes back into main!
"
\# file types<br>
*.cache<br>
*.dtbcache.v2<br>
*.dll<br>
*.pdb<br>
*.suo<br>
.suo<br>
*.testlog<br>
*.user<br>
\# directories<br>
**/Release
"
I had this problem with .cache files and the following steps solved it for me:
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With