my .gitignore
is as follows:
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# Project files
*.sln
*.vcxproj
*.vcxproj.filters
UpgradeLog.htm
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# ....
Now all of these files are ignored properly, with the exception of my solution file, main.sln
. Why is this not ignored when I specifically put it in the gitignore?
Is it due to the main.sln existing before I added it to the ignore? I thought it would just stop tracking it if I placed it within the ignore but I guess that's not the case. Here's a screenshot:
How can I simply stop tracking changes for main.sln
?
Lines in .gitignore
will only ignore files that are not part of the repository. Once they are added to the repository, they are tracked, and cannot be ignored.
If you want truly to stop traking this file you have to remove it from the git tree. Just do, from the command line:
$ git rm --cached main.sln
And then commit that change. From then on, your file will be gitignored.
NOTE: the --cached
option is to keep the real file in the working directory. Without it the file would also be deleted.
.gitignore
only works for untracked files. if files already tracked then it can not be ignored, If you added files to repository then two ways to solve it:
1).First way is to do:
git update-index --assume-unchanged <file>
From the doc:
git-update-index - Register file contents in the working tree to the index,
--assume-unchanged - When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index
2).Second way is to remove the file(s) from repository as below:
git rm --cached <file>
Explanation of command from git-scm-doc:
- git-rm - Remove files from the working tree and from the index
- --cached - Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone. (this means that file will be deleted from tree index not from real directory.)
<file>
- Files to remove. Fileglobs (e.g. *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you may need to shell-escape them. A leading directory name (e.g. dir to remove dir/file1 and dir/file2) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.
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